diff --git a/Cargo.lock b/Cargo.lock index 4077fb3..8188112 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -648,6 +648,12 @@ dependencies = [ "simple_asn1", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" version = "0.2.155" @@ -852,6 +858,7 @@ dependencies = [ "anyhow", "clap", "git2", + "lazy_static", "octocrab", "serde", "serde_yml", diff --git a/Cargo.toml b/Cargo.toml index 3777cf9..1490e5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" anyhow = "^1" clap = { version = "^4", features = ["derive", "env"] } git2 = "^0" +lazy_static = "^1" octocrab = "^0" serde = "^1" serde_yml = "^0" diff --git a/src/main.rs b/src/main.rs index f54947c..d0b8f56 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,19 +12,24 @@ use clap::builder::styling::Style; use clap::{Parser, Subcommand}; use git2::Repository; use images::ContainerImages; +use lazy_static::lazy_static; use octocrab::commits::PullRequestTarget; use octocrab::models::pulls; use octocrab::models::pulls::ReviewState; use octocrab::Octocrab; const BOLD_UNDERLINE: Style = Style::new().bold().underline(); +lazy_static! { + static ref GITHUB_TOKEN_HELP: String = format!( + "{BOLD_UNDERLINE}Environment variables:{BOLD_UNDERLINE:#} + GITHUB_TOKEN GitHub token to use for API requests +" + ); +} /// Program to simplify PCI double approval process across repositories #[derive(Parser)] -#[command(version, about, long_about = None, after_help = format!("{BOLD_UNDERLINE}Environment variables:{BOLD_UNDERLINE:#} - GITHUB_TOKEN GitHub token to use for API requests -"))] -#[command(propagate_version = true)] +#[command(version, about, long_about = None, after_help = GITHUB_TOKEN_HELP.to_string(), propagate_version = true)] // see https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/variables for environment variablesuse struct Cli { /// The git base ref to compare against @@ -53,25 +58,19 @@ struct Cli { } #[derive(Subcommand)] -#[command(propagate_version = true)] enum Commands { /// Analyzes commits in a repo and finds relevant reviews + #[command(after_help = GITHUB_TOKEN_HELP.to_string())] Repo { /// GitHub git remote to use remote: String, }, /// Analyzes a helm-charts repo, finds sources from values.yaml files and runs repo subcommand on them + #[command(after_help = GITHUB_TOKEN_HELP.to_string())] HelmChart { /// Git repository where to discover images.yaml files - #[arg( - short, - long, - env = "GITHUB_WORKSPACE", - hide_env_values = true, - required = false, - global = true - )] + #[arg(env = "GITHUB_WORKSPACE", hide_env_values = true, required = false, global = true)] workspace: String, }, }