Remove historical inspection commands
This commit is contained in:
@@ -26,12 +26,6 @@ Usage:
|
||||
weatherreporter generate hourly [--config PATH] [--units VALUE] [--tz NAME] [--out PATH] [--llm-debug-dir PATH] [--quiet]
|
||||
weatherreporter run morning [--config PATH] [--units VALUE] [--tz NAME] [--out-dir PATH] [--llm-debug-dir PATH] [--quiet]
|
||||
weatherreporter run evening [--config PATH] [--units VALUE] [--tz NAME] [--out-dir PATH] [--llm-debug-dir PATH] [--quiet]
|
||||
weatherreporter inspect reports [--config PATH] [--limit N]
|
||||
weatherreporter inspect metadata [--config PATH] RUN_ID
|
||||
weatherreporter inspect modules [--config PATH] RUN_ID
|
||||
weatherreporter inspect data-package [--config PATH] RUN_ID
|
||||
weatherreporter inspect prior [--config PATH] RUN_ID
|
||||
weatherreporter inspect sources [--config PATH] RUN_ID
|
||||
|
||||
Options:
|
||||
-h, --help Show this help message.
|
||||
@@ -108,8 +102,6 @@ func (r Runner) Run(ctx context.Context, args []string, stdout io.Writer, stderr
|
||||
}
|
||||
}
|
||||
return err
|
||||
case "inspect":
|
||||
return r.runInspect(ctx, args[1:], stdout)
|
||||
default:
|
||||
return fmt.Errorf("unknown command %q", args[0])
|
||||
}
|
||||
@@ -130,81 +122,6 @@ type generateOptions struct {
|
||||
Date string
|
||||
}
|
||||
|
||||
type inspectOptions struct {
|
||||
ConfigPath string
|
||||
Limit int
|
||||
RunID string
|
||||
}
|
||||
|
||||
type inspectRunCommand struct {
|
||||
Name string
|
||||
Inspect func(context.Context, app.InspectRunRequest) (any, error)
|
||||
}
|
||||
|
||||
var inspectRunCommands = []inspectRunCommand{
|
||||
{Name: "metadata", Inspect: func(ctx context.Context, req app.InspectRunRequest) (any, error) {
|
||||
return app.InspectMetadata(ctx, req)
|
||||
}},
|
||||
{Name: "modules", Inspect: func(ctx context.Context, req app.InspectRunRequest) (any, error) {
|
||||
return app.InspectModules(ctx, req)
|
||||
}},
|
||||
{Name: "data-package", Inspect: func(ctx context.Context, req app.InspectRunRequest) (any, error) {
|
||||
return app.InspectDataPackage(ctx, req)
|
||||
}},
|
||||
{Name: "prior", Inspect: func(ctx context.Context, req app.InspectRunRequest) (any, error) {
|
||||
return app.InspectPriorSnapshot(ctx, req)
|
||||
}},
|
||||
{Name: "sources", Inspect: func(ctx context.Context, req app.InspectRunRequest) (any, error) {
|
||||
return app.InspectSources(ctx, req)
|
||||
}},
|
||||
}
|
||||
|
||||
func (r Runner) runInspect(ctx context.Context, args []string, stdout io.Writer) error {
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("inspect requires a command")
|
||||
}
|
||||
command := args[0]
|
||||
switch command {
|
||||
case "reports":
|
||||
opts, err := parseInspectReportsFlags(args[1:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg, err := config.Load(config.LoadOptions{Path: opts.ConfigPath})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
records, err := app.InspectReports(ctx, app.InspectReportsRequest{Config: cfg, Limit: opts.Limit})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return writeJSON(stdout, records)
|
||||
default:
|
||||
for _, candidate := range inspectRunCommands {
|
||||
if candidate.Name == command {
|
||||
return runInspectRunCommand(ctx, stdout, candidate, args[1:])
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("unknown inspect command %q", command)
|
||||
}
|
||||
}
|
||||
|
||||
func runInspectRunCommand(ctx context.Context, stdout io.Writer, command inspectRunCommand, args []string) error {
|
||||
opts, err := parseInspectRunFlags(command.Name, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg, err := config.Load(config.LoadOptions{Path: opts.ConfigPath})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
value, err := command.Inspect(ctx, app.InspectRunRequest{Config: cfg, RunID: opts.RunID})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return writeJSON(stdout, value)
|
||||
}
|
||||
|
||||
func (r Runner) resolveGenerate(args []string) (app.GenerateRequest, error) {
|
||||
req, _, err := r.resolveGenerateAction(args)
|
||||
return req, err
|
||||
@@ -366,39 +283,6 @@ func parseRunFlags(args []string) (commonOptions, error) {
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
func parseInspectReportsFlags(args []string) (inspectOptions, error) {
|
||||
fs := flag.NewFlagSet("inspect reports", flag.ContinueOnError)
|
||||
fs.SetOutput(io.Discard)
|
||||
opts := inspectOptions{Limit: 20}
|
||||
fs.StringVar(&opts.ConfigPath, "config", "", "configuration file path")
|
||||
fs.IntVar(&opts.Limit, "limit", 20, "maximum reports to list")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return inspectOptions{}, err
|
||||
}
|
||||
if fs.NArg() > 0 {
|
||||
return inspectOptions{}, fmt.Errorf("unexpected argument %q", fs.Arg(0))
|
||||
}
|
||||
if opts.Limit < 0 {
|
||||
return inspectOptions{}, fmt.Errorf("limit must be zero or greater")
|
||||
}
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
func parseInspectRunFlags(command string, args []string) (inspectOptions, error) {
|
||||
fs := flag.NewFlagSet("inspect "+command, flag.ContinueOnError)
|
||||
fs.SetOutput(io.Discard)
|
||||
opts := inspectOptions{}
|
||||
fs.StringVar(&opts.ConfigPath, "config", "", "configuration file path")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return inspectOptions{}, err
|
||||
}
|
||||
if fs.NArg() != 1 {
|
||||
return inspectOptions{}, fmt.Errorf("inspect %s requires a run id", command)
|
||||
}
|
||||
opts.RunID = fs.Arg(0)
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
func addCommonFlags(fs *flag.FlagSet, opts *commonOptions, includeOutput bool) {
|
||||
fs.StringVar(&opts.ConfigPath, "config", "", "configuration file path")
|
||||
fs.StringVar(&opts.Units, "units", "", "weather API units")
|
||||
|
||||
Reference in New Issue
Block a user