Skip to content

Commit

Permalink
Support env based configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
liamdawson committed Mar 14, 2024
1 parent b96c65e commit e64e3c2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 13 additions & 13 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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
Expand Down Expand Up @@ -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,
}
Expand All @@ -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<String>,
#[arg(long, requires("organization"), value_hint = ValueHint::Other)]
#[arg(long, requires("organization"), value_hint = ValueHint::Other, env = "BUILDKITE_WAITER_PIPELINE")]
pub pipeline: Option<String>,
#[arg(long, value_hint = ValueHint::Other)]
#[arg(long, value_hint = ValueHint::Other, env = "BUILDKITE_WAITER_BRANCH")]
pub branch: Vec<String>,
#[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<String>,
#[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<String>,
#[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<String>,
}

#[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,

Expand All @@ -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,
}

0 comments on commit e64e3c2

Please sign in to comment.