diff --git a/CHANGELOG.md b/CHANGELOG.md index b36d40e..36ad1a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Output URL in message when a build is found - Fig completions +- Allow most options to be configured by environment variables ### Notes diff --git a/Cargo.toml b/Cargo.toml index 49717d9..b744db3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ notifica = { version = "3.0.2", optional = true } anyhow = "1.0.81" chrono = { version = "0.4.35", features = ["serde"] } chrono-humanize = "0.2.3" -clap = { version = "4.5.2", features = ["derive", "cargo"] } +clap = { version = "4.5.2", features = ["derive", "cargo", "env"] } console = "0.15.8" dialoguer = "0.11.0" fern = "0.6.2" diff --git a/src/cli.rs b/src/cli.rs index ce2f6f6..fa3753e 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -14,7 +14,7 @@ const ALLOWED_BUILD_STATE_VALUES: &[&str] = &[ "canceling", "skipped", "not_run", - "finished" + "finished", ]; #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, ValueEnum)] @@ -25,7 +25,7 @@ pub enum OutputType { /// Build state and browser URL StateUrl, /// No output - None + None, } #[derive(Debug, Parser, PartialEq, Clone)] // requires `derive` feature @@ -73,13 +73,13 @@ pub enum Commands { #[derive(Args, Debug, PartialEq, Clone)] pub struct ByNumberStrategyArgs { - #[arg(value_hint = ValueHint::Other)] + #[arg(value_hint = ValueHint::Other, env = "BUILDKITE_WAITER_ORGANIZATION")] /// Organization slug pub organization: String, - #[arg(value_hint = ValueHint::Other)] + #[arg(value_hint = ValueHint::Other, env = "BUILDKITE_WAITER_PIPELINE")] /// Pipeline slug pub pipeline: String, - #[arg(value_hint = ValueHint::Other)] + #[arg(value_hint = ValueHint::Other, env = "BUILDKITE_WAITER_BUILD_NUMBER")] /// Build number pub number: u32, } @@ -92,28 +92,28 @@ pub struct ByUrlStrategyArgs { #[derive(Args, Debug, PartialEq, Clone)] pub struct LatestStrategyArgs { - #[arg(long, value_hint = ValueHint::Other)] + #[arg(long, value_hint = ValueHint::Other, env = "BUILDKITE_WAITER_ORGANIZATION")] pub organization: Option, - #[arg(long, requires("organization"), value_hint = ValueHint::Other)] + #[arg(long, requires("organization"), value_hint = ValueHint::Other, env = "BUILDKITE_WAITER_PIPELINE")] pub pipeline: Option, - #[arg(long, value_hint = ValueHint::Other)] + #[arg(long, value_hint = ValueHint::Other, env = "BUILDKITE_WAITER_BRANCH")] pub branch: Vec, #[arg(long)] /// Find build by owner of the API Access Token (requires the "Read User" permission on the token) pub mine: bool, - #[arg(long, conflicts_with("mine"), value_hint = ValueHint::Other)] + #[arg(long, conflicts_with("mine"), value_hint = ValueHint::Other, env = "BUILDKITE_WAITER_CREATOR")] /// Find build by creator ID pub creator: Option, - #[arg(long, value_hint = ValueHint::Other)] + #[arg(long, value_hint = ValueHint::Other, env = "BUILDKITE_WAITER_COMMIT")] /// Find build by (long) commit hash pub commit: Option, - #[arg(long, value_parser = PossibleValuesParser::new(ALLOWED_BUILD_STATE_VALUES))] + #[arg(long, value_parser = PossibleValuesParser::new(ALLOWED_BUILD_STATE_VALUES), env = "BUILDKITE_WAITER_STATE")] pub state: Vec, } #[derive(Args, Debug, PartialEq, Clone)] pub struct RuntimeArgs { - #[arg(long, default_value = "3600", value_hint = ValueHint::Other)] + #[arg(long, default_value = "3600", value_hint = ValueHint::Other, env = "BUILDKITE_WAITER_TIMEOUT")] /// Maximum time to wait for the build, in seconds pub timeout: u32, @@ -132,6 +132,6 @@ pub struct OutputArgs { /// Never send a system notification pub no_notification: bool, - #[arg(long, value_enum, default_value_t = OutputType::StateUrl)] + #[arg(long, value_enum, default_value_t = OutputType::StateUrl, env = "BUILDKITE_WAITER_OUTPUT")] pub output: OutputType, }