-
Notifications
You must be signed in to change notification settings - Fork 261
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
Update clap dependency from v3 to v4.1 #1053
Conversation
62384f4
to
a71a7b2
Compare
Tests are failing in CI but passing locally, so I'm opening this up for review while I figure out if it's related to any changes here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this update PR @cardoso!
Indeed, I think there may be a few spots to adjust per updated clap usage; both of the e2e test failures seem to arise from either a flag now being unexpected (--env
) or a value not received (bindle connection string):
test integration_tests::e2e_tests::test_headers_env_routes has been running for over 60 seconds
error: unexpected argument '--env' found
and
Error: Failed to prepare configuration
Caused by:
Component hello requires a Bindle connection but none was specified
test integration_tests::e2e_tests::test_using_parcel_as_module_source ... FAILED
3f05911
to
56913e2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had a couple Qs/comments, otherwise looking great to me. Appreciative of the detail/attention required for this update!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cardoso took one more close look at the updated cli output and raised a few more comments around notable changes, mostly to check in with others...
version = version(), | ||
)] | ||
enum SpinApp { | ||
#[clap(subcommand, alias = "template")] | ||
#[command(subcommand, alias = "template")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Not a comment on this particular line.)
Using this opportunity to point out to other reviewers that clap 4.0.0+ has updated default display order. Whereas in 3.x.x the commands are alphabetically sorted, 4+ appears to defer to the order we declare commands here in code.
Previous to this PR (looking at SUBCOMMANDS
):
With this PR (looking at Commands
):
@itowlson (and others) -- Do we have a preference on ordering? If so, should we ensure commands are listed here in the order we'd like them displayed? (Or, I imagine there is a clap 4+ setting we might utilize, regardless of order in code.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eek, good catch. I'd be inclined to go for alphabetical - some tools (such as Cargo do try to group similar commands together, but I'm not sure if we have a strong enough notion of that at the moment. And if we do it, we should approach it intentionally rather than as part of a package rev.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I do anything here? Change the order by hand, force the old way, leave it be for now?
Using a flag would be fighting clap quite a bit as it wants to be WYSIWYG going forward.
New way seems better to make the code 1:1 with the OCD CLI.
New behavior:
Sorted order is derived by default
Sorting is turned on by cmd.next_display_order(None)
This is not recursive, it must be set on each level
The display order incrementing is mixed with arguments
This does make it slightly more difficult to predict
from: clap-rs/clap#3975
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the best bet is to change the order by hand, assuming we'd like to retain the current alphabetical order.
c1d019e
to
654eed2
Compare
let env_args = spin_app_env.iter().flat_map(|e| ["--env", e]).collect(); | ||
|
||
let trigger_args = vec!["--file", manifest_path, "--listen", &url]; | ||
|
||
let bindle_args = match bindle_url { | ||
Some(url) => vec!["--bindle-server", url], | ||
None => vec![], | ||
}; | ||
|
||
let args = vec![ | ||
vec!["up"], | ||
spin_args.to_vec(), | ||
bindle_args, | ||
env_args, | ||
trigger_args, | ||
] | ||
.into_iter() | ||
.flatten(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably worth mentioning I had to change this test. Clap changed the way it parses, so that --env was being seen as part of spin trigger and not spin up.
I could try to force it, but it's not going to be pretty. The old behavior seemed less correct since --env appeared after other args which were going to spin trigger.
If it's too risky of a change, I could try a workaround
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the note here. It looks like spin built from main is agnostic about ordering/precedence between default up opts and trigger-specific opts. They can be provided in either order, for example:
$ ./spin-main up -e foo=bar --listen 127.0.0.1:3333
Serving http://127.0.0.1:3333
Available Routes:
hello: http://127.0.0.1:3333/hello
A simple component that returns hello.
^C
$ ./spin-main up --listen 127.0.0.1:3333 -e foo=bar
Serving http://127.0.0.1:3333
Available Routes:
hello: http://127.0.0.1:3333/hello
A simple component that returns hello.
Additionally, default opts and trigger opts can be intermixed:
$ ./spin-main up --listen 127.0.0.1:3333 -e foo=bar --follow-all
Serving http://127.0.0.1:3333
Available Routes:
hello: http://127.0.0.1:3333/hello
A simple component that returns hello.
While spin built from this branch does appear to enforce ordering and won't allow intermixing of opts:
$ spin up -e foo=bar --listen 127.0.0.1:3333
Serving http://127.0.0.1:3333
Available Routes:
hello: http://127.0.0.1:3333/hello
A simple component that returns hello.
^C
$ spin up --listen 127.0.0.1:3333 -e foo=bar
error: unexpected argument '-e' found
Usage: spin trigger http [OPTIONS]
For more information, try '--help'.
Error: exit status: 2
$ spin up -e foo=bar --listen 127.0.0.1:3333 --direct-mounts
error: unexpected argument '--direct-mounts' found
Usage: spin trigger http <--listen <ADDRESS>|--tls-cert <TLS_CERT>|--tls-key <TLS_KEY>>
For more information, try '--help'.
Error: exit status: 2
I'd definitely like to see how we can maintain the current (main
) behavior and allow for arbitrary ordering of opts.
src/commands/build.rs
Outdated
pub up: bool, | ||
|
||
#[clap(requires = BUILD_UP_OPT)] | ||
#[arg(requires = BUILD_UP_OPT)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting; I'm not quite sure what is amiss, but I'm seeing behavior where spin build --up
claims add'l up opts are invalid. It's a breaking change, so we'll want to check this out.
With the examples/http-rust
app, using spin built from main
:
$ spin build --up --listen 127.0.0.1:3333
Executing the build command for component hello: cargo build --target wasm32-wasi --release
Finished release [optimized] target(s) in 0.03s
Successfully ran the build command for the Spin components.
Serving http://127.0.0.1:3333
Available Routes:
hello: http://127.0.0.1:3333/hello
A simple component that returns hello.
^C
And here using the binary built from this branch:
$ spin build --up --listen 127.0.0.1:3333
error: unexpected argument '--listen' found
note: to pass '--listen' as a value, use '-- --listen'
Usage: spin build <--file <APP_CONFIG_FILE>|--up|UP_ARGS>
For more information, try '--help'.
let env_args = spin_app_env.iter().flat_map(|e| ["--env", e]).collect(); | ||
|
||
let trigger_args = vec!["--file", manifest_path, "--listen", &url]; | ||
|
||
let bindle_args = match bindle_url { | ||
Some(url) => vec!["--bindle-server", url], | ||
None => vec![], | ||
}; | ||
|
||
let args = vec![ | ||
vec!["up"], | ||
spin_args.to_vec(), | ||
bindle_args, | ||
env_args, | ||
trigger_args, | ||
] | ||
.into_iter() | ||
.flatten(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the note here. It looks like spin built from main is agnostic about ordering/precedence between default up opts and trigger-specific opts. They can be provided in either order, for example:
$ ./spin-main up -e foo=bar --listen 127.0.0.1:3333
Serving http://127.0.0.1:3333
Available Routes:
hello: http://127.0.0.1:3333/hello
A simple component that returns hello.
^C
$ ./spin-main up --listen 127.0.0.1:3333 -e foo=bar
Serving http://127.0.0.1:3333
Available Routes:
hello: http://127.0.0.1:3333/hello
A simple component that returns hello.
Additionally, default opts and trigger opts can be intermixed:
$ ./spin-main up --listen 127.0.0.1:3333 -e foo=bar --follow-all
Serving http://127.0.0.1:3333
Available Routes:
hello: http://127.0.0.1:3333/hello
A simple component that returns hello.
While spin built from this branch does appear to enforce ordering and won't allow intermixing of opts:
$ spin up -e foo=bar --listen 127.0.0.1:3333
Serving http://127.0.0.1:3333
Available Routes:
hello: http://127.0.0.1:3333/hello
A simple component that returns hello.
^C
$ spin up --listen 127.0.0.1:3333 -e foo=bar
error: unexpected argument '-e' found
Usage: spin trigger http [OPTIONS]
For more information, try '--help'.
Error: exit status: 2
$ spin up -e foo=bar --listen 127.0.0.1:3333 --direct-mounts
error: unexpected argument '--direct-mounts' found
Usage: spin trigger http <--listen <ADDRESS>|--tls-cert <TLS_CERT>|--tls-key <TLS_KEY>>
For more information, try '--help'.
Error: exit status: 2
I'd definitely like to see how we can maintain the current (main
) behavior and allow for arbitrary ordering of opts.
src/commands/build.rs
Outdated
pub struct BuildUpArgs { | ||
#[arg(short, long, group = "UpArgs", required=true)] | ||
pub up: bool, | ||
#[command(flatten, next_help_heading="Up")] | ||
pub args: UpArgs | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice!
@@ -80,12 +82,13 @@ vergen = { version = "7", default-features = false, features = [ | |||
] } | |||
|
|||
[features] | |||
default = [] | |||
default = ["generate-completions"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added completions here just to make sure the less conventional features like build's --up
option aren't breaking it.
I'll make sure to remove once this is ready for review again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh, if this provides us with a better and more consistent way to #1032 then I'd love to have your feedback on that PR (or your own PR). Thanks! (I agree on not trying to shoehorn it into this one, of course.)
Signed-off-by: Matheus Cardoso <[email protected]>
Closing this since it's fallen behind. Will open a new one soon. |
Thanks @cardoso and apologies -- this has definitely been a busy period for the Spin project and particularly the CLI. Happy to help in any way I can. |
The current clap version could make it difficult to improve the CLI's DevX with the newest CLI practices.
The update by itself already makes some improvements, but I'm looking forward to using this new version to add new capabilities.
Here's the full changelog: https://github.com/clap-rs/clap/blob/master/CHANGELOG.md#400---2022-09-28
Leaving this as draft for now while I test this further, but it seems to be working fine.
Also decided to depend on #1052 to test these crate updates together rather than after merge.
Signed-off-by: Matheus Cardoso [email protected]