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

[bldr] Push common args into their subcommands to prevent mis-invoking. #1621

Merged
merged 1 commit into from Jan 5, 2017

Conversation

Projects
None yet
4 participants
@fnichol
Member

fnichol commented Jan 5, 2017

This change clears up a usability issue that I stumbled upon myself,
initially in core/bldr-api. I wanted to use a custom config and ran
the following:

bldr-api --config /path/to/config.toml start

To my confusion, no matter what I did, my config was not getting picked
up. Upon re-reading the code and double checking against the clap API, I
learned that the global attribute on an argument will leave the arg
match at the level it was provided by the user (and not also copied down
to the subcommand). This means that both of these invocations result in
a started service:

bldr-api --config /path/to/config.toml start
bldr-api start --config /path/to/config.toml

The catch is that only the second one actually applies the config. Oi.

This fix provided here drops the global attribute on the Arg and
pushes them down into the start subcommand. Currently all the Builder
services only provide a start subcommand but in the future additional
subcommands may be added. At this point there is some start hardcoding
that needs to be generalized anyway and any copious arg duplication can
be dealt with then.

The new behavior is as follows:

> bldr-api start --config /path/to/config.toml
> bldr-api --config /path/to/config.toml start
error: Found argument '--config' which wasn't expected, or isn't valid in this context

USAGE:
    bldr-api [SUBCOMMAND]

For more information try --help

Signed-off-by: Fletcher Nichol fnichol@nichol.ca

[bldr] Push common args into their subcommands to prevent mis-invoking.
This change clears up a usability issue that I stumbled upon myself,
initially in `core/bldr-api`. I wanted to use a custom config and ran
the following:

    bldr-api --config /path/to/config.toml start

To my confusion, no matter what I did, my config was not getting picked
up. Upon re-reading the code and double checking against the clap API, I
learned that the `global` attribute on an argument will leave the arg
match at the level it was provided by the user (and not also copied down
to the subcommand). This means that both of these invocations result in
a started service:

    bldr-api --config /path/to/config.toml start
    bldr-api start --config /path/to/config.toml

The catch is that only the second one actually applies the config. Oi.

This fix provided here drops the `global` attribute on the `Arg` and
pushes them down into the `start` subcommand. Currently all the Builder
services only provide a `start` subcommand but in the future additional
subcommands may be added. At this point there is some `start` hardcoding
that needs to be generalized anyway and any copious arg duplication can
be dealt with then.

The new behavior is as follows:

```sh
> bldr-api start --config /path/to/config.toml
```

```sh
> bldr-api --config /path/to/config.toml start
error: Found argument '--config' which wasn't expected, or isn't valid in this context

USAGE:
    bldr-api [SUBCOMMAND]

For more information try --help
```

Signed-off-by: Fletcher Nichol <fnichol@nichol.ca>

@fnichol fnichol added Bug labels Jan 5, 2017

@thesentinels

This comment has been minimized.

Show comment
Hide comment
@thesentinels

thesentinels Jan 5, 2017

Contributor

Thanks for the pull request! Here is what will happen next:

  1. Your PR will be reviewed by the maintainers
  2. If everything looks good, one of them will approve it, and your PR will be merged.

Thank you for contributing!

Contributor

thesentinels commented Jan 5, 2017

Thanks for the pull request! Here is what will happen next:

  1. Your PR will be reviewed by the maintainers
  2. If everything looks good, one of them will approve it, and your PR will be merged.

Thank you for contributing!

@adamhjk

This comment has been minimized.

Show comment
Hide comment
@adamhjk

adamhjk Jan 5, 2017

Contributor

This looks good - as always, your PR explanations are legendary.

Lame that it doesn't work the way one would expect with the global setting.

gif-keyboard-5672741902532227213

@thesentinels approve

Contributor

adamhjk commented Jan 5, 2017

This looks good - as always, your PR explanations are legendary.

Lame that it doesn't work the way one would expect with the global setting.

gif-keyboard-5672741902532227213

@thesentinels approve

@thesentinels

This comment has been minimized.

Show comment
Hide comment
@thesentinels

thesentinels Jan 5, 2017

Contributor

🤘 I am testing your branch against master before merging it. We do this to ensure that the master branch is never failing tests.

Contributor

thesentinels commented Jan 5, 2017

🤘 I am testing your branch against master before merging it. We do this to ensure that the master branch is never failing tests.

@thesentinels

This comment has been minimized.

Show comment
Hide comment
@thesentinels

thesentinels Jan 5, 2017

Contributor

:neckbeard: Travis CI has started testing this PR.

Contributor

thesentinels commented Jan 5, 2017

:neckbeard: Travis CI has started testing this PR.

@thesentinels

This comment has been minimized.

Show comment
Hide comment
@thesentinels

thesentinels Jan 5, 2017

Contributor

💖 Travis CI reports this PR passed.

It always makes me feel nice when humans approve of one anothers work. I'm merging this PR now.

I just want you and the contributor to answer me one question:

gif-keyboard-3280869874741411265

Contributor

thesentinels commented Jan 5, 2017

💖 Travis CI reports this PR passed.

It always makes me feel nice when humans approve of one anothers work. I'm merging this PR now.

I just want you and the contributor to answer me one question:

gif-keyboard-3280869874741411265

@thesentinels thesentinels merged commit 3992980 into master Jan 5, 2017

3 checks passed

DCO This commit has a DCO Signed-off-by line
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@thesentinels thesentinels deleted the fnichol/bldr-subcommand-args branch Jan 5, 2017

@fnichol

This comment has been minimized.

Show comment
Hide comment
@fnichol
Member

fnichol commented Jan 6, 2017

gif-keyboard-14819133391177303892

@eeyun eeyun added A-builder C-bug and removed Builder labels Jun 6, 2017

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