diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-20 21:14:11 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-20 21:14:11 +0200 |
| commit | 0d3e15caf1d09e94e66946bdbc98001465d7f9f7 (patch) | |
| tree | 6c72d1e20fc87e1d3e08644c02f1233b3033d6d7 /cmd | |
| parent | 59e86c9fd39308bc6b632e02ecf4d37265dabc91 (diff) | |
refactor: apply Go best practices and remove obsolete files
- Reorganize types.go: place types and constructors before methods
- Simplify main.go: improve flag handling and reduce code complexity
- Extract processRecordsFile() in aggregate.go: reduce function size, ensure immediate defer
- Change Reporter receivers to value semantics for read-only operations
- Fix wordWrap() function: properly account for line length with leading space
- Remove guprecords.raku: Go implementation is the primary version now
- Remove compare-with-raku.sh: no longer needed
- Update README.md and .gitignore accordingly
All tests pass: go test ./... and ./goprecords test
Amp-Thread-ID: https://ampcode.com/threads/T-019c7c73-58f9-7516-958d-f30eb17a3bff
Co-authored-by: Amp <amp@ampcode.com>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/goprecords/main.go | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/cmd/goprecords/main.go b/cmd/goprecords/main.go index 7807d1f..c608f78 100644 --- a/cmd/goprecords/main.go +++ b/cmd/goprecords/main.go @@ -14,28 +14,26 @@ import ( const defaultDB = "goprecords.db" func main() { - for _, arg := range os.Args[1:] { - if arg == "-version" || arg == "--version" { - fmt.Println(version.Version) - os.Exit(0) - } + if len(os.Args) > 1 && (os.Args[1] == "-version" || os.Args[1] == "--version") { + fmt.Println(version.Version) + return } - if len(os.Args) >= 2 { - switch os.Args[1] { - case "import": - runImport(os.Args[2:]) - return - case "query": - runQuery(os.Args[2:]) - return - case "test": - runTests() - return - } + if len(os.Args) < 2 { + runReportFromFiles(nil) + return } - runReportFromFiles(os.Args[1:]) + switch os.Args[1] { + case "import": + runImport(os.Args[2:]) + case "query": + runQuery(os.Args[2:]) + case "test": + runTests() + default: + runReportFromFiles(os.Args[1:]) + } } func runImport(args []string) { @@ -146,6 +144,9 @@ func runQuery(args []string) { } func runReportFromFiles(args []string) { + if args == nil { + args = []string{} + } fs := flag.NewFlagSet("goprecords", flag.ExitOnError) statsDir := fs.String("stats-dir", "", "The uptimed raw record input dir (required)") category := fs.String("category", "Host", "Category: Host, Kernel, KernelMajor, KernelName") |
