Skip to content

Commit

Permalink
feat(rust): upgrade to clap v4
Browse files Browse the repository at this point in the history
finish transition to command/arg
deactivate mut_subcommand/mut_arg for "help" (does not work as expected with upgraded version)
  • Loading branch information
hargut committed Sep 22, 2022
1 parent b240058 commit 40df091
Show file tree
Hide file tree
Showing 33 changed files with 53 additions and 44 deletions.
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
//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
4 changes: 2 additions & 2 deletions implementations/rust/ockam/ockam_command/src/service/start.rs
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
2 changes: 1 addition & 1 deletion implementations/rust/ockam/ockam_command/src/space/list.rs
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
2 changes: 1 addition & 1 deletion implementations/rust/ockam/ockam_command/src/vault/mod.rs
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

0 comments on commit 40df091

Please sign in to comment.