Sviluppo software con Claude Code
Dani Zysman
AI Curriculum Manager @ DataCamp

--artist — nome artista da cercare--format — output JSON o CSV--output — percorso file per i risultati| Pattern | Esempio | Quando usarlo |
|---|---|---|
| Obbligatorio | --artist "AC/DC" |
Deve essere fornito |
| Opzionale | --format json |
Ha un default sensato |
| Flag | --verbose |
Booleano on/off |
| Posizionale | reporter.py data.csv |
Input principale |
--help per ogni argomento> Use @PLAN.md to build reporter.py
Fatto! Creato reporter.py seguendo PLAN.md
Funzioni principali:
- get_db_connection() SQLite in sola lettura con convalida
- fetch_artist_stats() 4 query SQL per aggregati
- format_json/csv() Formattazione output
- write_output() Scrittura file
- parse_args() / main() Orchestrazione CLI
Funzionalità:
- Ricerca artista case-insensitive
- Dettaglio per album con ricavi
- Tutti i messaggi d'errore come da specifica
- Flag --db per test injection
import argparse, sqlite3, json, csv
def main():
parser = argparse.ArgumentParser()
...
args = parser.parse_args()
conn = sqlite3.connect("chinook.db")
# Query artist's albums and tracks...
if args.format == "json":
with open(args.output, "w") as f:
json.dump(data, f, indent=2)

> Use @PLAN.md to build test_reporter.py
Creato test_reporter.py: 31 test in 7 classi Copertura: - Connection DB valido, file mancante, file non valido - Stats Artista noto/sconosciuto, case-insensitive, multi-genere - JSON Formato, indentazione, serializzazione round-trip - CSV Due sezioni, generi separati da pipe, conteggio righe - File I/O Scrittura, sovrascrittura, percorso non scrivibile - CLI args Argomenti obbligatori, validazione scelte - Integration Output JSON/CSV, artista/DB non trovato, cleanup Usa un piccolo SQLite con seed: indipendente da chinook.dbTutti i 31 test superati!
Sviluppo software con Claude Code