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

ArgMatches::value_of should include arguments to subcommands #978

Closed
sgrif opened this issue Jun 3, 2017 · 21 comments
Closed

ArgMatches::value_of should include arguments to subcommands #978

sgrif opened this issue Jun 3, 2017 · 21 comments
Labels
C-bug Category: Updating dependencies
Milestone

Comments

@sgrif
Copy link

sgrif commented Jun 3, 2017

In Diesel CLI we are using a global argument in combination with subcommands. I'd expect matches.value_of("ARG") to return the argument regardless of where it appeared. However, in Diesel CLI (which is using clap 2.24.2), running diesel migration run --database-url something will complain that the argument isn't present. Running diesel migration --database-url something run works.

@kbknapp
Copy link
Member

kbknapp commented Jun 16, 2017

@sgrif apologies for the late reply, I've been out of town. Looking at the diesel source, this looks like a bug on clap's end. It should be a quick fix though. Let me see if I can get it put together today.

@kbknapp kbknapp added C: args C-bug Category: Updating dependencies labels Jun 16, 2017
@kbknapp
Copy link
Member

kbknapp commented Jun 16, 2017

@sgrif can you add AppSettings::PropagateGlobalValuesDown and see if it still gives you an error?

Why isn't this the default you ask? It wasn't possible a long time ago, so it was added after the fact 😜

@sgrif
Copy link
Author

sgrif commented Jun 17, 2017

I won't get to it for a few days, but yes I will see if that works. :)

@sgrif
Copy link
Author

sgrif commented Sep 25, 2017

It's been a lot of days, but I finally got around to trying this. The setting improves things, but still doesn't fix the problem.

Command diesel --db-url="" db drop diesel db --db-url="" drop diesel db drop --db-url=""
Without Setting Arg not found Arg not found Fine
With Setting Fine Arg not found Fine
Command diesel --db-url="" migration run diesel migration --db-url="" run diesel migration run --db-url=""
Without Setting Arg not found Fine Arg not found
With Setting Fine Fine Arg not found

@kbknapp
Copy link
Member

kbknapp commented Sep 25, 2017

No worries, I've been incredibly busy too. Thanks for all the details, once I'm back at a computer (I'm on mobile) I should be able to figure this one out quickly

@willmurphyscode
Copy link
Contributor

Do you know whether anyone is already working on this? If not, I'd like to try to fix it over the next few days.

@kbknapp
Copy link
Member

kbknapp commented Sep 28, 2017

@willmurphyscode

I get home from my travel tomorrow and was planning on checking it out then, but if you'd like to take a swing at it I'd be more than happy to mentor it and assist where needed. 👍

@willmurphyscode
Copy link
Contributor

@kbknapp I'll take a swing at it. I confirmed the issue locally with diesel, so I was going to write some failing tests to start with. What's the best place to reach out if I need hand or have a question?

@willmurphyscode
Copy link
Contributor

@kbknapp I've written some failing tests that show the issue: https://github.com/willmurphyscode/clap-rs/blob/propagate-values-down/tests/propagate_globals_down.rs#L52 but I'm a little bit lost trying to figure out exactly what to change needs to be made to make them pass. I've commented the tests in that link. Would you mind providing a little help when you have a chance?

@kbknapp
Copy link
Member

kbknapp commented Oct 4, 2017

@willmurphyscode

first_subcommand_can_access_global_arg_if_global_arg_is_last

Your hypothesis is correct which was initially by design.

To fix it, you'll have to bubble all these values back up just prior to validation occurring.

Some edge cases to watch out for would be program --global-arg some_value outer --global-arg other_value where multiple values aren't true. But this should just work because validation will occur after propagation.

second_subcommand_can_access_global_arg_if_global_arg_is_in_the_middle

You're probably right here too.

To solve it, you'll probably just need to add some recursive calls to ArgMatcher::propagate down through all subcommands.

@kbknapp
Copy link
Member

kbknapp commented Oct 4, 2017

I believe one or both of these cases are actually already fixed in 3.x just due to being a more clean code base...but I'll add this to the 3.x issue tracker just in case.

@willmurphyscode
Copy link
Contributor

willmurphyscode commented Oct 6, 2017

@kbknapp You say "one or both of these is fixed in 3.x." Does that mean that there's nothing to do here and people should just wait for 3.x? I've opened a PR with the tests (#1060) in case someone else wants to follow up, but beyond that I'm probably out of time to work on this issue.

@kbknapp
Copy link
Member

kbknapp commented Oct 7, 2017

You say "one or both of these is fixed in 3.x." Does that mean that there's nothing to do here and people should just wait for 3.x?

Since I'm not sure when I'll be able to finalize 3.x with my crazy work schedule right now, I'd rather fix them in 2.x in the mean time. I saw your comment in the PR about lack of time as well, so I can pick up where you left off. Thanks for starting this though 👍

@Freyskeyd
Copy link

@kbknapp I also can contribute to this issue.

I need some input to get started.

@kbknapp
Copy link
Member

kbknapp commented Oct 10, 2017

@Freyskeyd thanks! 👍

I would take the failing tests in #1060 and start with second_subcommand_can_access_global_arg_if_global_arg_is_in_the_middle as it will probably be easier to solve. It may be as easy as looping through all matched subcommands and recursively calling propagate.

If you run into any questions, feel free to ping me on Gitter since I'll get those notifications on my cell phone as well.

@kbknapp
Copy link
Member

kbknapp commented Oct 10, 2017

@willmurphyscode off topic, I saw your name on the upcoming Meetup this week I didn't know you were in the area! Looking forward to meeting you guys. 😄

@kbknapp
Copy link
Member

kbknapp commented Oct 18, 2017

#1070 fixes this. @sgrif could you test your use case against the current master branch? If it's good to go I can put out another version here soon.

@sgrif
Copy link
Author

sgrif commented Oct 22, 2017

Yes, this resolves my issue

@sgrif sgrif closed this as completed Oct 22, 2017
@sgrif
Copy link
Author

sgrif commented Oct 22, 2017

Would love a ping when a new version is released. :)

kbknapp added a commit that referenced this issue Oct 24, 2017
…ot being propagated properly or at all

Closes #1010
Closes #1061
Closes #978
@kbknapp
Copy link
Member

kbknapp commented Oct 24, 2017

@sgrif will do! The goal is to release before I leave for Rust Belt Rust 😉

@kbknapp
Copy link
Member

kbknapp commented Oct 25, 2017

@sgrif v2.27.0 is out on crates.io and contains these fixes :)

@kbknapp kbknapp mentioned this issue Nov 12, 2017
87 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Updating dependencies
Projects
None yet
Development

No branches or pull requests

4 participants