diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-06 16:04:43 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-06 16:04:43 +0200 |
| commit | cc4edee087143d656fc74067297f3f540b61362e (patch) | |
| tree | 7bd4b8bf841037b2fb19779d52cff6219c4fa070 /internal/flags/flags.go | |
| parent | a2d253f1e92578ccea95f962bbd1a1aebf190de1 (diff) | |
refactor: share collapse field validation lists (task 387)
Diffstat (limited to 'internal/flags/flags.go')
| -rw-r--r-- | internal/flags/flags.go | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/internal/flags/flags.go b/internal/flags/flags.go index cc6e70a..67842ab 100644 --- a/internal/flags/flags.go +++ b/internal/flags/flags.go @@ -10,6 +10,8 @@ import ( "sync" "sync/atomic" "time" + + "ior/internal/collapse" ) var ( @@ -23,24 +25,6 @@ func init() { current.Store(&defaults) } -var ( - validCollapsedFields = []string{ - "path", - "comm", - "tracepoint", - "pid", - "tid", - "flags", - } - - validCollapsedCounts = []string{ - "count", - "duration", - "durationToPrev", - "bytes", - } -) - type Flags struct { PidFilter int TidFilter int @@ -159,6 +143,8 @@ func Parse() error { func parse() error { cfg := NewFlags() + validFields := collapse.ValidFields() + validCounts := collapse.ValidCountFields() flag.IntVar(&cfg.PidFilter, "pid", cfg.PidFilter, "Filter for processes ID") flag.IntVar(&cfg.TidFilter, "tid", cfg.TidFilter, "Filter for thread ID") @@ -179,9 +165,9 @@ func parse() error { flag.DurationVar(&cfg.LiveInterval, "live-interval", cfg.LiveInterval, "Synthetic live flamegraph refresh interval for --testliveflames") flag.BoolVar(&cfg.TUIExportEnable, "tuiExport", cfg.TUIExportEnable, "Enable writing TUI snapshot export files") fields := flag.String("fields", "", - fmt.Sprintf("Comma separated list of fields to collapse, valid are: %v", validCollapsedFields)) + fmt.Sprintf("Comma separated list of fields to collapse, valid are: %v", validFields)) flag.StringVar(&cfg.CountField, "count", cfg.CountField, - fmt.Sprintf("Count field to collapse, valid are: %v", validCollapsedCounts)) + fmt.Sprintf("Count field to collapse, valid are: %v", validCounts)) if err := flag.CommandLine.Parse(os.Args[1:]); err != nil { return err } @@ -208,12 +194,12 @@ func parse() error { } for _, field := range cfg.CollapsedFields { - if !slices.Contains(validCollapsedFields, field) { + if !collapse.IsValidField(field) { return fmt.Errorf("invalid field for collapse: %s", field) } } - if !slices.Contains(validCollapsedCounts, cfg.CountField) { + if !collapse.IsValidCountField(cfg.CountField) { return fmt.Errorf("invalid count field: %s", cfg.CountField) } |
