The repository has a hand-maintained quick reference and workflow guides, but
no complete reference. An operator cannot browse the whole public CLI without
a built binary, and nothing ties the prose to the commands, so the two drift
apart silently.
Add cli/docs/reference: an index and one page per public command, generated
from the cobra tree nvkectl itself runs. Each page carries the command's
purpose, invocation and positional arguments, aliases, examples, local and
inherited options with types and defaults, the required and mutually exclusive
option groups, and a deprecation notice when it has one.
cobra's doc package writes the body of each page. It does not emit aliases,
deprecation notices, flag-group constraints or an index, and it never removes
the page of a deleted command, so internal/clidocs adds those around it. All
of it is read from the command, so there is no second catalogue to maintain.
Deterministic, so repeated generation from unchanged source produces identical
files:
- cobra's generated-on timestamp is switched off on every command.
- The NVKECTL_ and NKECTL_ variables are cleared before the tree is built.
Two of `bootstrap site`'s flag defaults -- --diagnostics-dir and --timeout
-- are read from the environment by the command constructor, through
internal/envalias, which still honours the old prefix. Without this the
pages would record whatever the generating shell happened to have set.
- HOME and the XDG config directory are pinned, and the build metadata is a
fixed placeholder.
Generation runs no command and contacts nothing: it builds the tree and reads
its metadata, so it needs no credential, kubeconfig, configured site or
cluster. newRootCmd is exported for it, which is what the move to an
importable package was for.
`make -C cli docs` regenerates and `make -C cli docs-check` verifies, failing
on output that is stale, missing, obsolete, or newly generated and never
committed. The check joins the generated-artefact gate, which already covers
the provisioned-provider manifest and the generated API code, and joins
`make gate` and `make preflight` locally.
Two commands lazily added by cobra needed initialising before the traversal,
or the root page would link to pages that were never written: `help` and
`completion`. cobra's doc package also calls InitDefaultHelpCmd on every
command it renders, not just the root, which invented a `help` subcommand
under each group command -- `nvkectl bootstrap help` is not a command -- so
each one is given a hidden help command first to decide what cobra adds.
Hidden commands and help topics are excluded, which is why `render` and
`inspect` do not appear; a deprecated command keeps its page for as long as it
still runs.
Constraints enforced inside RunE are invisible to cobra. Those on `config
set-site` and the two patch commands are now stated in the flag usage strings
and Long text, so --help and the reference agree. No behaviour changes: the
checks still run where they did, with the messages they had.
cobra/doc brings go-md2man and blackfriday into cli/go.mod. Neither is
reachable from ./cmd/nvkectl, so the shipped binary is unaffected and
THIRD_PARTY_NOTICES.md is unchanged.
Signed-off-by: Jonathan Meier <jomeier@nvidia.com>
2.3 KiB
AGENTS.md
Scope
These instructions apply to the cli/ Go module and its end-to-end test
fixtures.
Verification
Run these commands from cli/:
make fmt
make lint
make test
Run make preflight from the repository root before submission. The bootstrap
end-to-end test also requires nerdctl with containerd, a buildkitd for
nerdctl build to reach, Kind, /dev/vtpmx, and the CWE image. It does not
need Docker. It does need root — it installs an iptables rule and assigns an
address to a bridge — so run it under sudo.
After a dependency change, run go mod tidy in cli/ and make work-sync at
the repository root.
The command reference
docs/reference/ is generated from the command tree, one page per public
command. After any change to a command — a new command or subcommand, a
renamed flag, a changed default, edited help text, an added alias, a
deprecation — run:
make -C cli docs
and commit the result with the change that caused it. make -C cli docs-check
verifies it, and the merge gate fails when the committed pages do not match the
tree.
Do not edit the generated pages. A page says what the command's own metadata
says, so change the Short, Long, Example, Args, Aliases,
Deprecated or flag usage string on the command itself.
A constraint enforced only inside RunE is invisible to cobra, so it never
reaches the reference on its own. State it in the command's Long text or in
the flag's usage string, the way --nodes and --sitespec already say
(required).
Go documentation comments
- Start each exported declaration comment with the declaration name.
- State the API contract. Explain what the function accepts and returns, or what side effect it performs.
- Use established domain terms, such as "out-of-band provisioning" and "initial handshake."
- Do not put design rationale, implementation history, pull-request context, or a detailed implementation walkthrough in a function comment.
- Put necessary design rationale in a design document. Link to that document from the comment only when callers need the context to use the API correctly.
- Put short implementation comments next to non-obvious code. Explain why the code is necessary, not what the syntax does.
Follow the Go documentation comment guidance at https://go.dev/doc/comment#func.