Skip to content

--hints, --stats and --verbose are ignored on subcommands in release builds #954

Open

Description

@robzolkos

--hints has no effect in a release build. BASECAMP_HINTS=1 works.

$ basecamp url parse https://3.basecamp.com/1/buckets/2/todos/3 --hints --json | jq '.breadcrumbs | length'
null
$ BASECAMP_HINTS=1 basecamp url parse https://3.basecamp.com/1/buckets/2/todos/3 --json | jq '.breadcrumbs | length'
3

Seen with a make build binary (version 0.17.1-…, not dev) and no hints key in config. A dev build hides the bug, because version.IsDev() turns hints on by default.

Cause. resolvePreferences is called from the root's PersistentPreRunE with cmd set to the subcommand being run. It asks cmd.PersistentFlags().Changed("hints"). A subcommand's own persistent flag set does not contain the root's --hints, so Changed is false and the config or IsDev() default overwrites the explicit flag:

if !pf.Changed("hints") && (!pf.Changed("no-hints") || !flags.NoHints) {

--stats and --verbose share the check. For --stats, the config value or the IsDev() default overrides the explicit flag. For --verbose, a config value does. --no-hints still works, because App.OK reads flags.NoHints directly. root_test.go calls resolvePreferences with the root command, where PersistentFlags() does hold the flags, so it passes.

Fix. Use cmd.Flags().Changed(...), which includes inherited persistent flags once parsed. Add a test that runs a subcommand with --hints against a non-dev version.

Found while verifying #950.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions