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

Update Rust crate clap to v4 #50

Merged
merged 5 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "mcf"
version = "0.17.0"
edition = "2021"
default-run = "mcf"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -13,8 +14,8 @@ lto = true
opt-level = 0

[dependencies]
clap = { version = "3.2.25", features = ["derive"] }
clap_complete = "3.2.5"
clap = { version = "4.4.8", features = ["derive"] }
clap_complete = "4.4.4"
dirs = "5.0.1"
anyhow = "1.0.75"
log = "0.4.20"
Expand Down
12 changes: 6 additions & 6 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ use lib::{
use std::{io, path::PathBuf, sync::Arc};

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
#[clap(name = "mcf")]
#[clap(bin_name = "mcf")]
#[command(author, version, about, long_about = None)]
#[command(name = "mcf")]
#[command(bin_name = "mcf")]
struct Mcf {
#[clap(subcommand)]
#[command(subcommand)]
command: Subcommands,

/// Overwrite mcf config path
#[clap(long, global = true)]
#[arg(long, global = true)]
override_path: Option<String>,

/// Overwrite binary name for cloudfoundry cli (for example: "cf8")
#[clap(long, global = true)]
#[arg(long, global = true)]
cf_binary_name: Option<String>,
}

Expand Down
7 changes: 4 additions & 3 deletions cli/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ pub enum EnvironmentCommands {
Add {
name: String,
url: String,
#[clap(long)]
#[arg(long)]
sso: bool,
#[clap(long)]
#[arg(long)]
skip_ssl_validation: bool,
},
#[clap(visible_alias = "rm")]
/// Remove an environment to the environment list
#[command(visible_alias = "rm")]
Remove { name: String },
/// List all the environment you stored
#[command(visible_alias = "ls")]
List,
}

Expand Down
21 changes: 11 additions & 10 deletions cli/src/subcommands.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
use crate::environment::EnvironmentCommands;
use clap::Subcommand;
use clap_complete::Shell;

#[derive(clap::Subcommand, Debug)]
#[derive(Subcommand, Debug)]
pub enum Subcommands {
/// Add, Remove, List environment (example cf-dev)
#[clap(visible_alias = "env")]
#[command(visible_alias = "env")]
Environment {
#[clap(subcommand)]
#[command(subcommand)]
environment_commands: EnvironmentCommands,
},
/// Login to one of the Cloud Foundry environments
#[clap(visible_alias = "l")]
#[command(visible_alias = "l")]
Login {
/// Name of the environment (example "cf-dev")
name: String,
/// One-time passcode
#[clap(long)]
#[arg(long)]
sso_passcode: Option<String>,
/// Cloudfoundry organization
#[clap(short,long)]
#[arg(short,long)]
org: Option<String>,
/// Cloudfoundry space
#[clap(short,long)]
#[arg(short,long)]
space: Option<String>,
},
/// Execute command on Cloud Foundry environment
#[clap(visible_alias = "e", trailing_var_arg = true)]
#[command(visible_alias = "e", trailing_var_arg = true)]
Exec {
/// Names of the environments (example "cf-dev,cf-prod")
names: String,
/// Command you want to execute (example "logs your-application --recent")
command: Vec<String>,
/// Execute command sequentially (example "ssh your-application")
#[clap(short, long)]
#[arg(short, long)]
sequential_mode: bool
},
/// Generate shell autocompletion files
Completion {
#[clap(arg_enum, value_parser)]
#[arg(value_enum)]
shell: Shell,
},
}
37 changes: 16 additions & 21 deletions integration/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,24 @@ fn can_run_mcf() {
cmd.arg("-h");
cmd.assert().success();
let expected_output = format!(
r###"
USAGE:
mcf [OPTIONS] <SUBCOMMAND>
r###"Usage: mcf [OPTIONS] <COMMAND>

OPTIONS:
--cf-binary-name <CF_BINARY_NAME>
Overwrite binary name for cloudfoundry cli (for example: "cf8")
Commands:
environment Add, Remove, List environment (example cf-dev) [aliases: env]
login Login to one of the Cloud Foundry environments [aliases: l]
exec Execute command on Cloud Foundry environment [aliases: e]
completion Generate shell autocompletion files
help Print this message or the help of the given subcommand(s)

-h, --help
Print help information

--override-path <OVERRIDE_PATH>
Overwrite mcf config path

-V, --version
Print version information

SUBCOMMANDS:
completion Generate shell autocompletion files
environment Add, Remove, List environment (example cf-dev) [aliases: env]
exec Execute command on Cloud Foundry environment [aliases: e]
help Print this message or the help of the given subcommand(s)
login Login to one of the Cloud Foundry environments [aliases: l]
Options:
--override-path <OVERRIDE_PATH>
Overwrite mcf config path
--cf-binary-name <CF_BINARY_NAME>
Overwrite binary name for cloudfoundry cli (for example: "cf8")
-h, --help
Print help
-V, --version
Print version
"###
);
let actual_output = String::from_utf8(cmd.assert().get_output().to_owned().stdout).unwrap();
Expand Down
Loading