From 8fb1df8aa65a52cdb4a7e1bb9dda9b912a7a2895 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Thu, 19 Jan 2023 04:43:37 +0200 Subject: [PATCH] feat(cli): add `--ci` flag to `signer generate`, closes #6089 (#6097) Co-authored-by: Lucas Nogueira --- .changes/cli-sign-non-interactive.md | 6 ++++++ tooling/cli/src/signer/generate.rs | 12 +++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 .changes/cli-sign-non-interactive.md diff --git a/.changes/cli-sign-non-interactive.md b/.changes/cli-sign-non-interactive.md new file mode 100644 index 000000000..473dad10c --- /dev/null +++ b/.changes/cli-sign-non-interactive.md @@ -0,0 +1,6 @@ +--- +"cli.rs": patch +"cli.js": patch +--- + +Add `--ci` flag and respect the `CI` environment variable on the `signer generate` command. In this case the default password will be an empty string and the CLI will not prompt for a value. diff --git a/tooling/cli/src/signer/generate.rs b/tooling/cli/src/signer/generate.rs index 03a518ef4..5a1094bf6 100644 --- a/tooling/cli/src/signer/generate.rs +++ b/tooling/cli/src/signer/generate.rs @@ -21,11 +21,17 @@ pub struct Options { /// Overwrite private key even if it exists on the specified path #[clap(short, long)] force: bool, + /// Skip prompting for values + #[clap(short, long)] + ci: bool, } -pub fn command(options: Options) -> Result<()> { - if options.password.is_none() { - println!("Generating new private key without password.") +pub fn command(mut options: Options) -> Result<()> { + options.ci = options.ci || std::env::var("CI").is_ok(); + + if options.ci && options.password.is_none() { + println!("Generating new private key without password."); + options.password.replace("".into()); } let keypair = generate_key(options.password).expect("Failed to generate key");