Skip to content

refactor: move the root command to internal/cmd - #476

Merged
thde merged 4 commits into
mainfrom
refactor/root-command
Oct 16, 2026
Merged

thde merged 4 commits into
mainfrom
refactor/root-command

Conversation

@thde

@thde thde commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Suggested command lines no longer depend on os.Args[0],
so hints read nctl like the usage output does,
regardless of how the binary was invoked.
GetCmd no longer lowercases its arguments in place,
and the unused SetOrg is gone.

The client is now a singleton provider,
so kong only builds it for commands whose Run method takes an *api.Client.
This replaces the list of command names
which had to be kept in sync with the command tree.
A failing client setup is reported as a cli.Error like other errors.

main only wires the process to cmd.Run:
signals, arguments, standard streams, the version and the exit code.
Run returns the exit code instead of exiting,
turning the exits kong performs into a return,
so the whole CLI can be tested in-process.

The missing-command hint no longer exits by itself,
a second signal still terminates nctl with signal.NotifyContext,
and only the root command may import the verbs.

The tests guard the layering below the root command,
so they live next to it as deps_test.go, after go/build/deps_test.go.
They find the module root through go.mod
instead of relying on the working directory.

@thde
thde added this pull request to stack #479 October 15, 2026 13:05
@thde
thde force-pushed the refactor/root-command branch 4 times, most recently from 1223f5a to 8b53d7c Compare October 15, 2026 14:00
thde added 4 commits October 15, 2026 16:07
Suggested command lines no longer depend on os.Args[0],
so hints read nctl like the usage output does,
regardless of how the binary was invoked.
GetCmd no longer lowercases its arguments in place,
and the unused SetOrg is gone.
The client is now a singleton provider,
so kong only builds it for commands whose Run method takes an *api.Client.
This replaces the list of command names
which had to be kept in sync with the command tree.
A failing client setup is reported as a cli.Error like other errors.
main only wires the process to cmd.Run:
signals, arguments, standard streams, the version and the exit code.
Run returns the exit code instead of exiting,
turning the exits kong performs into a return,
so the whole CLI can be tested in-process.

The missing-command hint no longer exits by itself,
a second signal still terminates nctl with signal.NotifyContext,
and only the root command may import the verbs.
The tests guard the layering below the root command,
so they live next to it as deps_test.go, after go/build/deps_test.go.
They find the module root through go.mod
instead of relying on the working directory.
@thde
thde force-pushed the refactor/root-command branch from 8b53d7c to 8735c40 Compare October 15, 2026 14:07

@SaadAssaf SaadAssaf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@thde
thde merged commit 0c4e880 into main Oct 16, 2026
3 checks passed
@thde
thde deleted the refactor/root-command branch October 16, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants