Skip to content

Conversation

lima-limon-inc
Copy link

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 with midenup invocation of the client under the miden 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.

.map(|executable| {
executable
.file_name()
.expect("ERROR: failed to obtain the executable's file name")
Copy link
Author

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

Copy link
Collaborator

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"))
Copy link
Author

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.

Comment on lines 75 to 77
#[command(multicall(true))]
pub struct MidenClientCLI {
#[command(subcommand)]
action: Command,
behavior: Behavior,
}

Copy link
Author

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.

Copy link
Collaborator

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

@lima-limon-inc lima-limon-inc changed the title feat: make client's CLI multicall feat: make the client's cli multicall aware Aug 7, 2025
@lima-limon-inc lima-limon-inc force-pushed the fabrizioorsi-multicall-cli branch from c3af25b to f644498 Compare August 7, 2025 16:02
@lima-limon-inc lima-limon-inc changed the title feat: make the client's cli multicall aware feat: add multicall suuport for the CLI Aug 7, 2025
@lima-limon-inc lima-limon-inc marked this pull request as ready for review August 7, 2025 16:03
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();
Copy link
Collaborator

@igamigo igamigo Aug 7, 2025

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());

Copy link
Author

@lima-limon-inc lima-limon-inc Aug 7, 2025

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

)]
pub struct Cli {
#[command(multicall(true))]
pub struct MidenClientCLI {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pub struct MidenClientCLI {
pub struct MidenClientCli {

Copy link
Author

@lima-limon-inc lima-limon-inc Aug 7, 2025

Choose a reason for hiding this comment

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

Renamed here: 3f35b2f

@lima-limon-inc lima-limon-inc force-pushed the fabrizioorsi-multicall-cli branch from 45d073c to 3f35b2f Compare August 7, 2025 18:47
@lima-limon-inc
Copy link
Author

Heads up! I'm squashing and rebasing this and opening a PR upstream.

@lima-limon-inc lima-limon-inc force-pushed the fabrizioorsi-multicall-cli branch 3 times, most recently from 9e0c870 to 53f9fe3 Compare August 8, 2025 13:06
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>
@lima-limon-inc lima-limon-inc force-pushed the fabrizioorsi-multicall-cli branch from 53f9fe3 to f49b5c4 Compare August 8, 2025 17:22
lima-limon-inc and others added 4 commits August 11, 2025 10:56
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants