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

Feature/clap v4 wip #3514

Closed
wants to merge 10 commits into from
4 changes: 2 additions & 2 deletions implementations/rust/ockam/ockam_command/src/admin/mod.rs
Expand Up @@ -10,10 +10,10 @@ const HELP_DETAIL: &str = "";
#[derive(Clone, Debug, Args)]
#[command(hide = help::hide(), help_template = help::template(HELP_DETAIL))]
pub struct AdminCommand {
#[clap(subcommand)]
#[command(subcommand)]
pub subcommand: AdminSubCommand,

#[clap(flatten)]
#[command(flatten)]
pub cloud_opts: CloudOpts,
}

Expand Down
Expand Up @@ -20,10 +20,10 @@ const HELP_DETAIL: &str = "";
#[derive(Clone, Debug, Args)]
#[command(hide = help::hide(), help_template = help::template(HELP_DETAIL))]
pub struct SubscriptionCommand {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: SubscriptionSubcommand,

#[clap(flatten)]
#[command(flatten)]
cloud_opts: CloudOpts,
}

Expand Down Expand Up @@ -71,7 +71,7 @@ pub enum SubscriptionSubcommand {

#[derive(Clone, Debug, Args)]
pub struct SubscriptionUpdate {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: SubscriptionUpdateSubcommand,
}

Expand Down
Expand Up @@ -12,7 +12,7 @@ const HELP_DETAIL: &str = "";
#[derive(Clone, Debug, Args)]
#[command(hide = help::hide(), help_template = help::template(HELP_DETAIL))]
pub struct AuthenticatedCommand {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: AuthenticatedSubcommand,
}

Expand Down
Expand Up @@ -19,7 +19,7 @@ const HELP_DETAIL: &str = "";
#[derive(Clone, Debug, Args)]
#[command(hide = help::hide(), help_template = help::template(HELP_DETAIL))]
pub struct ConfigurationCommand {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: ConfigurationSubcommand,
}

Expand Down
Expand Up @@ -16,7 +16,7 @@ use clap::{Args, Subcommand};
subcommand_required = true
)]
pub struct CredentialCommand {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: CredentialSubcommand,
}

Expand Down
Expand Up @@ -10,7 +10,7 @@ use crate::CommandGlobalOpts;

#[derive(Clone, Debug, Args)]
pub struct PresentCredentialCommand {
#[clap(flatten)]
#[command(flatten)]
pub node_opts: NodeOpts,

#[arg(long, display_order = 900, id = "ROUTE")]
Expand Down
2 changes: 1 addition & 1 deletion implementations/rust/ockam/ockam_command/src/enroll.rs
Expand Up @@ -31,7 +31,7 @@ const HELP_DETAIL: &str = "";
#[derive(Clone, Debug, Args)]
#[command(help_template = help::template(HELP_DETAIL))]
pub struct EnrollCommand {
#[clap(flatten)]
#[command(flatten)]
pub cloud_opts: CloudOpts,
}

Expand Down
Expand Up @@ -55,7 +55,7 @@ ABOUT:
help_template = help::template(HELP_DETAIL)
)]
pub struct ForwarderCommand {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: ForwarderSubCommand,
}

Expand Down
Expand Up @@ -11,7 +11,7 @@ use ockam_core::Route;
#[derive(Clone, Debug, Args)]
#[command(hide = help::hide())]
pub struct CreateCommand {
#[clap(flatten)]
#[command(flatten)]
node_opts: NodeOpts,
}

Expand Down
Expand Up @@ -10,7 +10,7 @@ use clap::{Args, Subcommand};
/// Manage Identities
#[derive(Clone, Debug, Args)]
pub struct IdentityCommand {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: IdentitySubcommand,
}

Expand Down
8 changes: 6 additions & 2 deletions implementations/rust/ockam/ockam_command/src/lib.rs
Expand Up @@ -148,8 +148,12 @@ EXAMPLES:
version,
long_version = Version::long(),
next_help_heading = "GLOBAL OPTIONS",
mut_arg("help", |a| a.help_heading("GLOBAL OPTIONS")),
mut_subcommand("help", |c| c.about("Print help information"))
// TODO: mut_arg & mut_subcommand for help
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mrinalwadhwa
The previously used mut_arg & mut_subcommand for help lead with the new version to runtime errors like:

thread 'main' panicked at 'Argument `help` is undefined'
thread 'main' panicked at 'Command `help` is undefined'

So it seems that mut_ on "help" does not work any more as in the previous version. I've check the docs, but could not locate any indication that this was removed or disabled. Further the upgrade guide is not providing an information this is no longer possible.

https://docs.rs/clap/4.0.0-rc.2/clap/_derive/index.html
https://docs.rs/clap/4.0.0-rc.2/clap/struct.Command.html#method.mut_subcommand

Did I miss something?

It looks like "help" is no longer part of the clap::builder::command::Command subcommands Vec and therefore mut_subcommand fails on trying to mutate "help".
At top level with the mut_arg it seems to be a similar situation. Trying to add "help" leads to a duplicate error, and only works out after disable_help_flag = true.

Best regards,
Harald

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for researching that, makes sense. In the refactor to clap v4, I think we can disable the use of mut_arg and mut_subcommand ... get everything working in the new version. And then add the change suggested in clap-rs/clap#4056

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just had a look at the first test run results, but cannot understand what was going on:

The checkout action states:
https://github.com/build-trust/ockam/actions/runs/3108456670/jobs/5043177038#step:3:485

478:  HEAD is now at 0207e5a Merge 40df091a79a724158272f306e4a88f46279cfc98 into fe6e34b8f824ff3b56a3482a62c9ba8e652c7d64

One error from the build is:
https://github.com/build-trust/ockam/actions/runs/3108456670/jobs/5043177038#step:7:57

 56: error: Unknown `#[clap(long)]` attribute (`#[arg(long)] exists)
  --> implementations/rust/ockam/ockam_command/src/node/create.rs:87:12
   |
87 |     #[clap(long, hide = true)]
   |            ^^^^

The file does not contain any #[clap( at commit 40df091.

😕 😲

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, the part originates from a commit that was not there when the change was created:

fe6e34b#diff-afac108b9e4f2377c7932bef242708078b72d74836268ccc0ff4a09a24f67a53R87

//disable_help_flag = true,
//arg = Arg::new("help"),
//mut_arg("help", |a| a.help_heading("GLOBAL OPTIONS")),
//subcommand(Command::new("help")),
//mut_subcommand("help", |c| c.about("Print help information"))
)]
pub struct OckamCommand {
#[command(subcommand)]
Expand Down
5 changes: 3 additions & 2 deletions implementations/rust/ockam/ockam_command/src/message/mod.rs
Expand Up @@ -87,10 +87,11 @@ EXAMPLES:
arg_required_else_help = true,
subcommand_required = true,
help_template = help::template(HELP_DETAIL),
mut_subcommand("help", |c| c.about("Print help information"))
// TODO: mut_subcommand
// mut_subcommand("help", |c| c.about("Print help information"))
)]
pub struct MessageCommand {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: MessageSubcommand,
}

Expand Down
5 changes: 3 additions & 2 deletions implementations/rust/ockam/ockam_command/src/node/mod.rs
Expand Up @@ -119,10 +119,11 @@ EXAMPLES:
arg_required_else_help = true,
subcommand_required = true,
help_template = help::template(HELP_DETAIL),
mut_subcommand("help", |c| c.about("Print help information"))
// TODO: mut_subcommand
// mut_subcommand("help", |c| c.about("Print help information"))
)]
pub struct NodeCommand {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: NodeSubcommand,
}

Expand Down
Expand Up @@ -14,13 +14,13 @@ use crate::{stop_node, CommandGlobalOpts, Result};
#[derive(Clone, Debug, Args)]
pub struct GetCredentialCommand {
/// Orchestrator address to resolve projects present in the `at` argument
#[clap(flatten)]
#[command(flatten)]
cloud_opts: CloudOpts,

#[clap(flatten)]
#[command(flatten)]
node_opts: NodeOpts,

#[clap(long, short)]
#[arg(long, short)]
to: MultiAddr,
}

Expand Down
Expand Up @@ -12,7 +12,7 @@ use crate::CommandGlobalOpts;
/// List projects
#[derive(Clone, Debug, Args)]
pub struct ListCommand {
#[clap(flatten)]
#[command(flatten)]
pub cloud_opts: CloudOpts,
}

Expand Down
Expand Up @@ -31,7 +31,7 @@ use crate::CommandGlobalOpts;
#[derive(Clone, Debug, Args)]
#[command(arg_required_else_help = true, subcommand_required = true)]
pub struct ProjectCommand {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: ProjectSubcommand,
}

Expand Down
Expand Up @@ -13,7 +13,7 @@ use crate::{help, CommandGlobalOpts};
#[command(arg_required_else_help = true, help_template = help::template(HELP_DETAIL))]
pub struct ListCommand {
/// Node of which secure listeners shall be listed
#[clap(flatten)]
#[command(flatten)]
node_opts: NodeOpts,
}

Expand Down
Expand Up @@ -14,7 +14,8 @@ use clap::{Args, Subcommand};
arg_required_else_help = true,
subcommand_required = true,
help_template = help::template(HELP_DETAIL),
mut_subcommand("help", |c| c.about("Print help information"))
// TODO: mut_subcommand
// mut_subcommand("help", |c| c.about("Print help information"))
)]
pub struct SecureChannelListenerCommand {
#[command(subcommand)]
Expand Down
Expand Up @@ -142,10 +142,11 @@ ABOUT:
arg_required_else_help = true,
subcommand_required = true,
help_template = help::template(HELP_DETAIL),
mut_subcommand("help", |c| c.about("Print help information"))
// TODO: mut_subcommand
// mut_subcommand("help", |c| c.about("Print help information"))
)]
pub struct SecureChannelCommand {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: SecureChannelSubcommand,
}

Expand Down
Expand Up @@ -10,7 +10,7 @@ use clap::{Args, Subcommand};
#[derive(Clone, Debug, Args)]
#[command(hide = help::hide())]
pub struct ServiceCommand {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: ServiceSubcommand,
}

Expand Down
Expand Up @@ -18,10 +18,10 @@ use tracing::debug;

#[derive(Clone, Debug, Args)]
pub struct StartCommand {
#[clap(flatten)]
#[command(flatten)]
pub node_opts: NodeOpts,

#[clap(subcommand)]
#[command(subcommand)]
pub create_subcommand: StartSubCommand,
}

Expand Down
Expand Up @@ -14,7 +14,7 @@ pub struct DeleteCommand {
#[arg(display_order = 1001)]
pub name: String,

#[clap(flatten)]
#[command(flatten)]
pub cloud_opts: CloudOpts,
}

Expand Down
Expand Up @@ -11,7 +11,7 @@ use crate::CommandGlobalOpts;

#[derive(Clone, Debug, Args)]
pub struct ListCommand {
#[clap(flatten)]
#[command(flatten)]
pub cloud_opts: CloudOpts,
}

Expand Down
5 changes: 3 additions & 2 deletions implementations/rust/ockam/ockam_command/src/space/mod.rs
Expand Up @@ -19,10 +19,11 @@ pub mod util;
#[command(
arg_required_else_help = true,
subcommand_required = true,
mut_subcommand("help", |c| c.about("Print help information")),
// TODO: mut_subcommand
// mut_subcommand("help", |c| c.about("Print help information")),
)]
pub struct SpaceCommand {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: SpaceSubcommand,
}

Expand Down
Expand Up @@ -11,7 +11,7 @@ use ockam_api::nodes::{

#[derive(Args, Clone, Debug)]
pub struct ListCommand {
#[clap(flatten)]
#[command(flatten)]
node_opts: NodeOpts,
}

Expand Down
Expand Up @@ -12,7 +12,7 @@ use clap::{Args, Subcommand};
/// Manage TCP Connections
#[derive(Args, Clone, Debug)]
pub struct TcpConnectionCommand {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: TcpConnectionSubCommand,
}

Expand Down
Expand Up @@ -7,7 +7,7 @@ use create::CreateCommand;
/// Manage TCP Inlets
#[derive(Clone, Debug, Args)]
pub struct TcpInletCommand {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: TcpInletSubCommand,
}

Expand Down
Expand Up @@ -15,7 +15,7 @@ use std::str::FromStr;

#[derive(Args, Clone, Debug)]
pub struct CreateCommand {
#[clap(flatten)]
#[command(flatten)]
node_opts: TCPListenerNodeOpts,

/// Address for this listener (eg. 127.0.0.1:7000)
Expand Down
Expand Up @@ -11,7 +11,7 @@ use ockam_api::nodes::{

#[derive(Args, Clone, Debug)]
pub struct ListCommand {
#[clap(flatten)]
#[command(flatten)]
node_opts: NodeOpts,
}

Expand Down
Expand Up @@ -12,7 +12,7 @@ use clap::{Args, Subcommand};
/// Manage TCP Listeners
#[derive(Args, Clone, Debug)]
pub struct TcpListenerCommand {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: TcpListenerSubCommand,
}

Expand Down
Expand Up @@ -7,7 +7,7 @@ use create::CreateCommand;
/// Manage TCP Outlets
#[derive(Clone, Debug, Args)]
pub struct TcpOutletCommand {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: TcpOutletSubCommand,
}

Expand Down
Expand Up @@ -9,7 +9,7 @@ use ockam_core::Route;
/// Create vaults
#[derive(Clone, Debug, Args)]
pub struct CreateCommand {
#[clap(flatten)]
#[command(flatten)]
node_opts: NodeOpts,

/// Path to the Vault storage file
Expand Down
Expand Up @@ -9,7 +9,7 @@ use clap::{Args, Subcommand};
#[derive(Clone, Debug, Args)]
#[command(hide = help::hide())]
pub struct VaultCommand {
#[clap(subcommand)]
#[command(subcommand)]
subcommand: VaultSubcommand,
}

Expand Down