-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add multicall
suuport for the CLI
#24
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
base: next
Are you sure you want to change the base?
Conversation
bin/miden-cli/src/lib.rs
Outdated
.map(|executable| { | ||
executable | ||
.file_name() | ||
.expect("ERROR: failed to obtain the executable's file name") |
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 went for an expect
here since this function only returns None
if the file ends in ..
, which should be possible in this case.
Source: https://doc.rust-lang.org/std/path/struct.Path.html#method.file_name
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.
You mean it should be possible only if someone manually renames the executable, right?
Defaulting to miden-client." | ||
); | ||
}) | ||
.unwrap_or(OsString::from("miden-client")) |
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.
If, for whatever reason, current_exe
fails to return the executable's name, I went with returning a default. Mainly because the error case scenario is a bit far fetched, for instance, deleting the executable file during execution (for more details, see: https://doc.rust-lang.org/std/env/fn.current_exe.html#errors).
Worst case scenario, the displayed message is invalid, but we do get a diagnostic thanks to inspect_err
.
#[command(multicall(true))] | ||
pub struct MidenClientCLI { | ||
#[command(subcommand)] | ||
action: Command, | ||
behavior: Behavior, | ||
} | ||
|
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.
We require a "wrapper" struct when using multicall
because argv[0]
gets stripped (see docs, and the executable name gets treated directly as the argument.
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.
We should document the MidenClientCLI
a bit more to reflect this IMO
c3af25b
to
f644498
Compare
multicall
suuport for the CLI
bin/miden-cli/src/main.rs
Outdated
let cli = Cli::parse(); | ||
let input = <MidenClientCLI as clap::CommandFactory>::command(); | ||
let matches = input.get_matches(); | ||
let parsed = MidenClientCLI::from_arg_matches(&matches).map_err(|err| err.exit()).unwrap(); |
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.
This unwrap
looks like it could be removed
let parsed = MidenClientCLI::from_arg_matches(&matches)
.unwrap_or_else(|err| err.exit());
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.
Good catch! Changed here: 01d4588
bin/miden-cli/src/lib.rs
Outdated
)] | ||
pub struct Cli { | ||
#[command(multicall(true))] | ||
pub struct MidenClientCLI { |
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.
pub struct MidenClientCLI { | |
pub struct MidenClientCli { |
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.
Renamed here: 3f35b2f
45d073c
to
3f35b2f
Compare
Heads up! I'm squashing and rebasing this and opening a PR upstream. |
9e0c870
to
53f9fe3
Compare
Signed-off-by: Tomas Fabrizio Orsi <tomas.orsi@lambdaclass.com>
Suggested-by: Francisco Krause Arnim <francisco.krause@lambdaclass.com> Signed-off-by: Tomas Fabrizio Orsi <tomas.orsi@lambdaclass.com>
53f9fe3
to
f49b5c4
Compare
Signed-off-by: Tomas Fabrizio Orsi <tomas.orsi@lambdaclass.com>
Signed-off-by: Tomas Fabrizio Orsi <tomas.orsi@lambdaclass.com>
Signed-off-by: Tomas Fabrizio Orsi <tomas.orsi@lambdaclass.com>
Signed-off-by: Tomas Fabrizio Orsi <tomas.orsi@lambdaclass.com>
This PR makes the client's CLI multicall compatible. With this, the client's CLI is aware of whether it is being called under the
miden-client
name or a different one, like it is the case withmidenup
invocation of the client under themiden client
name.This value is stored in the
Cli
struct, although it is not being currently used.Besides, the
CLIENT_BINARY_NAME
constant was replaced in favor of function that returns the name by which the client's executable was called.