diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-14 11:31:39 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-14 11:31:39 +0300 |
| commit | 0b090c2698607fcdef039fb703c8c6bac5fceca0 (patch) | |
| tree | 77b3ba27e9f07d128115cd5a41ac6c2f6db8c01b /internal/cli/cmd_report_from_files.go | |
| parent | 0165352a63cb2f78871c2e72d4f2fd4f111637c3 (diff) | |
refactor(cli): split run* handlers into files (ask 24)
Move runImport, runQuery, runReportFromFiles, runDaemon,
runCreateClientKey, and runTests into dedicated cmd_*.go files.
Keep Execute routing in cli.go. defaultListenFromEnv stays with daemon.
Made-with: Cursor
Diffstat (limited to 'internal/cli/cmd_report_from_files.go')
| -rw-r--r-- | internal/cli/cmd_report_from_files.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/cli/cmd_report_from_files.go b/internal/cli/cmd_report_from_files.go new file mode 100644 index 0000000..ca2bb8c --- /dev/null +++ b/internal/cli/cmd_report_from_files.go @@ -0,0 +1,38 @@ +package cli + +import ( + "context" + "flag" + "fmt" + "os" + + "codeberg.org/snonux/goprecords/internal/goprecords" +) + +func runReportFromFiles(args []string) error { + if args == nil { + args = []string{} + } + fs := flag.NewFlagSet("goprecords", flag.ExitOnError) + statsDir := fs.String("stats-dir", "", "The uptimed raw record input dir (required)") + rf := goprecords.RegisterReportFlags(fs) + if err := fs.Parse(args); err != nil { + return err + } + if *statsDir == "" { + fmt.Fprintln(os.Stderr, "missing required flag: -stats-dir") + fs.Usage() + return fmt.Errorf("missing -stats-dir") + } + cfg, err := rf.Parse() + if err != nil { + return err + } + ctx := context.Background() + aggr := goprecords.NewAggregator(*statsDir) + aggregates, err := aggr.Aggregate(ctx) + if err != nil { + return err + } + return goprecords.WriteReports(os.Stdout, aggregates, cfg) +} |
