Skip to content

cmd/gonix: replace alecthomas/kong with stdlib flag#8

Open
aldoborrero wants to merge 1 commit intomainfrom
aldo/replace-kong-with-stdlib
Open

cmd/gonix: replace alecthomas/kong with stdlib flag#8
aldoborrero wants to merge 1 commit intomainfrom
aldo/replace-kong-with-stdlib

Conversation

@aldoborrero
Copy link
Copy Markdown
Member

The gonix CLI is small — 4 subcommands, 2 flags, 7 positional args. Well within stdlib flag's reach.

Approach

  • main.go dispatches on os.Args[1] to nar.Main() / drv.Main()
  • Each subpackage's Main() builds a flag.FlagSet per subcommand and reads positionals from fs.Args()
  • The custom drv-store-uri kong mapper becomes a plain derivationStore.NewFromURI call after parsing

Per-subcommand files (cat.go, dump.go, ls.go, show.go) keep their Cmd structs and Run() methods unchanged — only the kong struct tags are stripped. Help text and arg-count validation become explicit.

Behavior preserved

$ gonix nar dump-path cmd/gonix/nar > /tmp/test.nar
$ gonix nar ls -R /tmp/test.nar
-r-xr-xr-x /
-r--r--r-- /cat.go (907 bytes)
...
$ gonix nar cat /tmp/test.nar /cmd.go | head -1
package nar
$ gonix drv show --format aterm /nix/store/...drv
Derive([("out",...

Error paths (unknown command, missing positionals, --help) all produce sensible output.

Dependency reduction

Drops alecthomas/kong and transitively alecthomas/repr + pkg/errors from go.sum. First of a small series trimming the dependency surface.

The gonix CLI is small (4 subcommands, 2 flags, 7 positionals) — well
within stdlib flag's reach. Dispatch on os.Args[1] in main, then each
subpackage's Main() builds a FlagSet per subcommand and reads positionals
from fs.Args(). The custom drv-store-uri kong mapper becomes a plain
NewFromURI call after flag parsing.

Per-subcommand files (cat.go, dump.go, ls.go, show.go) keep their Cmd
structs and Run() methods; only the kong struct tags are stripped. Help
text and arg-count validation are explicit.

Drops alecthomas/kong (and transitively alecthomas/repr, pkg/errors)
from go.mod.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant