summaryrefslogtreecommitdiff
path: root/internal/cli/cmd_report_from_files.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cli/cmd_report_from_files.go')
-rw-r--r--internal/cli/cmd_report_from_files.go38
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)
+}