Skip to content

Commit

Permalink
Merge pull request #35 from buildkite/help-and-version-flags
Browse files Browse the repository at this point in the history
Add `--help` and `--version` args
  • Loading branch information
pda authored Mar 13, 2024
2 parents e7908db + 7aa5143 commit ec317a9
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,31 @@ use std::io::*;
static BATCH_SIZE: usize = 500;
static ENDPOINT: &str = "https://analytics-api.buildkite.com/v1/uploads";

// https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates
const NAME: &str = env!("CARGO_PKG_NAME");
const VERSION: &str = env!("CARGO_PKG_VERSION");

/// The entrypoint for the binary. Takes no arguments.
///
/// ## Emits warnings
/// - If the CI environment cannot be detected.
fn main() {
let mut args = std::env::args();
let prog = args.next().unwrap_or(NAME.to_string());
while let Some(arg) = args.next() {
match arg.as_str() {
"--version" => {
println!("{} {}", NAME, VERSION);
return;
}
"--help" => {
help(prog);
return;
}
_ => {}
}
}

let stdin = std::io::stdin();
let stdin = stdin.lock();

Expand All @@ -78,3 +98,21 @@ fn main() {
}
}
}

fn help(prog: String) {
println!("\n{} {}", NAME, VERSION);
print!(
"
Expects BUILDKITE_ANALYTICS_TOKEN in environment, and test result JSON on stdin.
Test results may be piped like:
cargo test -- -Z unstable-options --format json --report-time | {}
For more help, see:
- https://buildkite.com/docs/test-analytics/rust-collectors
- https://github.com/buildkite/test-collector-rust
",
prog
);
}

0 comments on commit ec317a9

Please sign in to comment.