Skip to content

fix(skywire-cli): error on unknown subcommand under combined 'skywire cli' - #4074

Open
0pcom wants to merge 1 commit into
skycoin:developfrom
0pcom:fix/cli-unknown-subcommand-error
Open

fix(skywire-cli): error on unknown subcommand under combined 'skywire cli'#4074
0pcom wants to merge 1 commit into
skycoin:developfrom
0pcom:fix/cli-unknown-subcommand-error

Conversation

@0pcom

@0pcom 0pcom commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Problem

skywire cli <unknown-subcommand> (e.g. skywire cli bogus) printed the ASCII banner instead of erroring. The standalone skywire-cli bogus errors cleanly.

Cause: under the combined skywire binary, cli is a non-root command. Cobra's legacyArgs only does unknown-subcommand checking for a parent-less root, so the stray arg passes; and cobra's !Runnable() check fires before ValidateArgs, so a non-runnable cli returns flag.ErrHelp and prints the banner. The standalone binary avoids this because cli's RootCmd is the root there.

Fix

In cmd/skywire-cli/commands/root.go:

  • add Args: cobra.NoArgs so a leftover positional (unknown subcommand) is rejected;
  • add a RunE that prints help, making cli runnable so cobra reaches arg validation instead of short-circuiting to ErrHelp.

Validation (combined + standalone binaries built locally)

  • skywire cli bogusunknown command "bogus" for "skywire cli", exit 1 (was: banner).
  • skywire cli (bare) → still prints help (same as before).
  • skywire cli version and other valid subcommands → unaffected.
  • skywire-cli bogus (standalone) → still errors; skywire-cli bare → still prints help.

Backward-compatible: only the previously-misleading banner-on-typo path changes.

@0pcom
0pcom force-pushed the fix/cli-unknown-subcommand-error branch from d6d203b to dfebc4c Compare August 22, 2026 14:16
… cli'

Bare `skywire cli <unknown>` printed the ASCII banner instead of an
error. Cause: under the combined `skywire` binary, `cli` is a non-root
command, so cobra's legacyArgs skips subcommand checking (that only runs
for a parent-less root), and cobra's `!Runnable()` check fires before
arg validation — a non-runnable `cli` returns ErrHelp and prints the
banner. The standalone `skywire-cli` errors correctly because it is the
root.

Make `cli` runnable via a RunE that prints help (matching the old
bare-invocation output) and add Args: cobra.NoArgs so cobra reaches arg
validation and rejects the stray arg. `skywire cli bogus` now errors
cleanly; bare `skywire cli` still prints help; valid subcommands are
unaffected.
@0pcom
0pcom force-pushed the fix/cli-unknown-subcommand-error branch from dfebc4c to b258e38 Compare August 22, 2026 14:55
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