Skip to content

fix(help): show command flags in 'fastly help <subcommand>' matching '--help' - #1972

Open
Tyagiquamar wants to merge 1 commit into
fastly:mainfrom
Tyagiquamar:fix/950-help-subcommand-flags
Open

Tyagiquamar wants to merge 1 commit into
fastly:mainfrom
Tyagiquamar:fix/950-help-subcommand-flags

Conversation

@Tyagiquamar

Copy link
Copy Markdown
Contributor

Problem

Running fastly <subcommand> --help displays command-specific flags under REQUIRED FLAGS and OPTIONAL FLAGS, followed by GLOBAL FLAGS. However, running fastly help <subcommand> (e.g. fastly help service create) only prints GLOBAL FLAGS and completely omits the subcommand's required and optional flags, as well as its detailed description.

Root cause

In pkg/app/usage.go, VerboseUsageTemplate (the template used when parsing Kingpin help commands via app.Parse("help ...")) only included blocks for SUBCOMMANDS and GLOBAL FLAGS. It lacked template directives to render .Context.SelectedCommand.Help as well as .Context.Flags|RequiredFlags and .Context.Flags|OptionalFlags. As a result, help requested via fastly help <subcommand> dropped all command-specific flags and descriptions.

Fix

  1. Updated VerboseUsageTemplate in pkg/app/usage.go to include:
    • Command description rendering via {{.Context.SelectedCommand.Help|Wrap 0}} when .Context.SelectedCommand.Help is present.
    • REQUIRED FLAGS block using {{if .Context.Flags|RequiredFlags -}}.
    • OPTIONAL FLAGS block using {{if .Context.Flags|OptionalFlags -}}.
  2. Added unit regression tests in pkg/app/run_test.go (TestHelpSubcommandFlags) verifying that fastly help service create and fastly help service alert create properly output OPTIONAL FLAGS, REQUIRED FLAGS, and GLOBAL FLAGS.

Validation

  • Ran go test -v ./pkg/app (all tests passed, including TestHelpSubcommandFlags).
  • Executed fastly help service create and fastly help service alert create against the built binary and verified that required, optional, and global flags are displayed consistently with <subcommand> --help.
  • Ran gofmt on modified files.

Related issue

Fixes #950

…'--help'

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>
@github-actions

Copy link
Copy Markdown

Thanks for the contribution! This pull request doesn't follow our pull request template:

  • the ### Change summary section is missing
  • the All Submissions: checklist is missing

Please edit the description to use the template. If it is still missing after 3 days, this pull request will be closed automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

output for fastly subcommand help and fastly subcommand --help don't match

1 participant