Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove parent command's flags from subcommand usage #44

Merged
merged 3 commits into from
Jan 6, 2019

Conversation

mdippery
Copy link
Contributor

A change related to #42 allowed subcommands to inherit flags from their parent. Unfortunately, this change has resulted in some duplication of flags. As shown in the example above, the flags -h, -v, and -t were printed twice in the help output when help for subcommands are shown, which is unexpected and looks a bit odd. It's especially pronounced in subcommands in which the parent command does not have any flags; two blocks for -h, -v, and -t are printed consecutively now, like this:

Options:
            --date FORMAT  Show dates in "absolute" or "relative" format
            --grep STRING  Show only comments matching STRING
  -n LIMIT, --limit LIMIT  Only show n comments
            --oneline      Output log in a more compact form
            --raw          Print raw comment bodies
        -h, --help         Show this message
        -v, --version      Print the name and version
        -t, --trace        Show the full backtrace when an error occurs
        -h, --help         Show this message
        -v, --version      Print the name and version
        -t, --trace        Show the full backtrace when an error occurs

This change corrects that so that flags for subcommands are only printed once.

@crispgm
Copy link
Member

crispgm commented Oct 13, 2016

Found this issue, too. Both on my personal programs and Jekyll.

@parkr would you mind reviewing and merging this to fix the issue?

@mdippery mdippery mentioned this pull request Dec 6, 2018
Issue jekyll#42 introduced the ability for subcommands to print help output
that includes its parent's flags. Unfortunately, this duplicated some
flags, such as `-h`, `-v`, and `-t`, that are also considered to be a
part of the subcommand. This makes the usage output look a bit odd, as
these flags are printed twice. This commit removes that duplication; it
does not print help output for flags that are also part of the parent
command's flags.
Copy link
Member

@ashmaroli ashmaroli left a comment

Choose a reason for hiding this comment

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

I like the end-result but not the route proposed. Left a couple of comments to address
Thank you.

lib/mercenary/presenter.rb Outdated Show resolved Hide resolved
lib/mercenary/presenter.rb Outdated Show resolved Hide resolved
it "can tell whether it is a parent command or not" do
expect(command.root?).to be true
expect(command_with_parent.root?).to be false
end
Copy link
Member

Choose a reason for hiding this comment

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

You should ideally be testing the issue at hand (which is in Presenter)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this test for the time being and will write a better one.

Copy link
Member

Choose a reason for hiding this comment

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

Take your time. Don't forget to remove Command#root? if it no longer has a role..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added tests and removed Command#root?.

It is more direct to just check the truthiness of Command#parent
instead.
Copy link
Member

@ashmaroli ashmaroli left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

Copy link
Member

@DirtyF DirtyF left a comment

Choose a reason for hiding this comment

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

Thanks @mdippery

@DirtyF
Copy link
Member

DirtyF commented Jan 6, 2019

@jekyllbot: merge +minor

:shipit:

@jekyllbot jekyllbot merged commit 452b719 into jekyll:master Jan 6, 2019
jekyllbot added a commit that referenced this pull request Jan 6, 2019
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.

5 participants