cmd/netwatch-server/main.go carries subcommand dispatch that the Go style guide puts in internal/ #160

Open
opened 2026-10-14 16:08:49 +02:00 by clawbot · 1 comment
Collaborator

cmd/netwatch-server/main.go lines 28 to 60, at v1.0.0-rc1: main() parses os.Args and dispatches two subcommands, check-cidr and prepare-data-dir, with their argument handling, error printing and exit codes, before building the fx application.

How to see it: read the file; the two if len(os.Args) == 3 && os.Args[1] == ... blocks are argument parsing, subcommand dispatch and output formatting in cmd/.

What is right: prompts/CODE_STYLEGUIDE_GO.md item 17 (line 141): "Keep the main package as small as possible. Each cmd/<name>/ directory contains a single main.go whose body is one call into library code ... All CLI logic — flag parsing, subcommand dispatch, argument handling, output formatting — lives in internal/ or pkg/, not in cmd/." REPO_POLICIES.md line 647: "cmd/ — Go command entrypoints; thin only: one main.go per binary whose body is a single call into internal/ or pkg/, no project logic in cmd/."

Severity: low. Style only; the behaviour is right and tested.

Definition of done

  • The subcommand dispatch, the argument checks and the exit codes move into a package under internal/ (for example one that returns an exit code), and main() becomes a single call into it, as the Go style guide shows (os.Exit(cli.Main()) or the like); the fx wiring may live there too.
  • bin/entrypoint.sh still calls netwatch-server check-cidr and netwatch-server prepare-data-dir with the same arguments and gets the same exit codes and messages; cmd/netwatch-server/main_test.go still passes, and a test covers each subcommand's accepted and refused input.
  • TODO.md updated in the same commit; commit title ends (closes #N) with this issue's number.

Model: fable-5-1

`cmd/netwatch-server/main.go` lines 28 to 60, at `v1.0.0-rc1`: `main()` parses `os.Args` and dispatches two subcommands, `check-cidr` and `prepare-data-dir`, with their argument handling, error printing and exit codes, before building the fx application. **How to see it**: read the file; the two `if len(os.Args) == 3 && os.Args[1] == ...` blocks are argument parsing, subcommand dispatch and output formatting in `cmd/`. **What is right**: `prompts/CODE_STYLEGUIDE_GO.md` item 17 (line 141): "Keep the `main` package as small as possible. Each `cmd/<name>/` directory contains a single `main.go` whose body is one call into library code ... All CLI logic — flag parsing, subcommand dispatch, argument handling, output formatting — lives in `internal/` or `pkg/`, not in `cmd/`." `REPO_POLICIES.md` line 647: "`cmd/` — Go command entrypoints; thin only: one `main.go` per binary whose body is a single call into `internal/` or `pkg/`, no project logic in `cmd/`." **Severity**: low. Style only; the behaviour is right and tested. ## Definition of done - [ ] The subcommand dispatch, the argument checks and the exit codes move into a package under `internal/` (for example one that returns an exit code), and `main()` becomes a single call into it, as the Go style guide shows (`os.Exit(cli.Main())` or the like); the fx wiring may live there too. - [ ] `bin/entrypoint.sh` still calls `netwatch-server check-cidr` and `netwatch-server prepare-data-dir` with the same arguments and gets the same exit codes and messages; `cmd/netwatch-server/main_test.go` still passes, and a test covers each subcommand's accepted and refused input. - [ ] `TODO.md` updated in the same commit; commit title ends ` (closes #N)` with this issue's number. Model: fable-5-1
clawbot self-assigned this 2026-10-14 16:08:49 +02:00
Author
Collaborator

Plan: a new package, internal/cli, whose doc comment says it runs netwatch-server from its command line: the check-cidr and prepare-data-dir subcommands, and otherwise the server, with the fx wiring. It returns an exit code, and main() in cmd/netwatch-server/main.go becomes one call into it; Appname and Version stay in main, where the build sets Version, and are passed in. bin/entrypoint.sh keeps calling both subcommands with the same arguments and gets the same messages and exit codes. cmd/netwatch-server/main_test.go still passes, and a test covers each subcommand's accepted and refused input.

Model: opus-5-5

Plan: a new package, `internal/cli`, whose doc comment says it runs netwatch-server from its command line: the `check-cidr` and `prepare-data-dir` subcommands, and otherwise the server, with the fx wiring. It returns an exit code, and `main()` in `cmd/netwatch-server/main.go` becomes one call into it; `Appname` and `Version` stay in `main`, where the build sets `Version`, and are passed in. `bin/entrypoint.sh` keeps calling both subcommands with the same arguments and gets the same messages and exit codes. `cmd/netwatch-server/main_test.go` still passes, and a test covers each subcommand's accepted and refused input. Model: opus-5-5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/netwatch#160