From 70d95e1ce9d98639cbe6309afcb62a6f1d787637 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 16 Jan 2024 04:02:09 +0000 Subject: [PATCH 1/3] CI: Run rage tests This requires specifying all feature flags manually, as we can't use --all-features without enabling the `rage/mount` feature flag which only works on some runners. --- .github/workflows/ci.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 088a4f2e..1380c386 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,11 +12,20 @@ jobs: steps: - uses: actions/checkout@v4 - - run: cargo fetch - - name: Build tests - run: cargo build --workspace --verbose --exclude rage --all-features --tests - name: Run tests - run: cargo test --workspace --verbose --exclude rage --all-features + run: > + cargo test + --workspace + --features ' + armor + async + cli-common + plugin + ssh + unstable + ' + - name: Verify working directory is clean + run: git diff --exit-code build: name: Build target ${{ matrix.target }} From 201f21ff568df5314cc2fd82f6ee8d89722d71c8 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 16 Jan 2024 04:04:33 +0000 Subject: [PATCH 2/3] rage: Fix CLI tests --- rage/tests/cmd/rage-keygen/help.toml | 6 +++++- rage/tests/cmd/rage-keygen/help_it.toml | 6 +++++- rage/tests/cmd/rage/help.toml | 8 ++++---- rage/tests/cmd/rage/help_it.toml | 8 ++++---- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/rage/tests/cmd/rage-keygen/help.toml b/rage/tests/cmd/rage-keygen/help.toml index 58ef3fdb..bfdee1b8 100644 --- a/rage/tests/cmd/rage-keygen/help.toml +++ b/rage/tests/cmd/rage-keygen/help.toml @@ -1,11 +1,15 @@ bin.name = "rage-keygen" args = "--help" stdout = """ -Usage: rage-keygen[EXE] [OPTIONS] +Usage: rage-keygen[EXE] [OPTIONS] [INPUT] + +Arguments: + [INPUT] Path to a file to read from. Options: -h, --help Print this help message and exit. -V, --version Print version info and exit. -o, --output Write the result to the file at path OUTPUT. Defaults to standard output. + -y Convert an identity file to a recipients file. """ stderr = "" diff --git a/rage/tests/cmd/rage-keygen/help_it.toml b/rage/tests/cmd/rage-keygen/help_it.toml index 3922b9e4..759ea753 100644 --- a/rage/tests/cmd/rage-keygen/help_it.toml +++ b/rage/tests/cmd/rage-keygen/help_it.toml @@ -2,11 +2,15 @@ bin.name = "rage-keygen" args = "--help" env.add.LANG = "it" stdout = """ -Usage: rage-keygen[EXE] [OPTIONS] +Usage: rage-keygen[EXE] [OPTIONS] [INPUT] + +Arguments: + [INPUT] Path to a file to read from. Options: -h, --help Print this help message and exit. -V, --version Print version info and exit. -o, --output Write the result to the file at path OUTPUT. Defaults to standard output. + -y Convert an identity file to a recipients file. """ stderr = "" diff --git a/rage/tests/cmd/rage/help.toml b/rage/tests/cmd/rage/help.toml index 7e875b07..d7ccff10 100644 --- a/rage/tests/cmd/rage/help.toml +++ b/rage/tests/cmd/rage/help.toml @@ -24,7 +24,7 @@ Options: INPUT defaults to standard input, and OUTPUT defaults to standard output. RECIPIENT can be: -- An age public key, as generated by rage-keygen ("age1..."). +- An age public key, as generated by rage-keygen[EXE] ("age1..."). - An SSH public key ("ssh-ed25519 AAAA...", "ssh-rsa AAAA..."). PATH is a path to a file containing age recipients, one per line @@ -36,9 +36,9 @@ Passphrase-encrypted age identity files can be used as identity files. Multiple identities may be provided, and any unused ones will be ignored. Example: - $ rage-keygen -o key.txt + $ rage-keygen[EXE] -o key.txt Public key: age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p - $ tar cvz ~/data | rage -r age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p > data.tar.gz.age - $ rage -d -i key.txt -o data.tar.gz data.tar.gz.age + $ tar cvz ~/data | rage[EXE] -r age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p > data.tar.gz.age + $ rage[EXE] -d -i key.txt -o data.tar.gz data.tar.gz.age """ stderr = "" diff --git a/rage/tests/cmd/rage/help_it.toml b/rage/tests/cmd/rage/help_it.toml index 6d4f81d0..8692c6c5 100644 --- a/rage/tests/cmd/rage/help_it.toml +++ b/rage/tests/cmd/rage/help_it.toml @@ -26,7 +26,7 @@ INPUT ha come valore predefinito lo standard input, e OUTPUT ha come valore predefinito lo standard output. RECIPIENT può essere: -- Una chiave pubblica age, come generata da rage-keygen ("age1..."). +- Una chiave pubblica age, come generata da rage-keygen[EXE] ("age1..."). - Una chiave pubblica SSH ("ssh-ed25519 AAAA...", "ssh-rsa AAAA..."). PATH è il percorso ad un file contenente dei destinatari age, @@ -39,9 +39,9 @@ I file di identità possono essere cifrati con age e una passphrase. Possono essere fornite più identità, quelle inutilizzate verranno ignorate. Esempio: - $ rage-keygen -o key.txt + $ rage-keygen[EXE] -o key.txt Chiave pubblica: age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p - $ tar cvz ~/data | rage -r age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p > data.tar.gz.age - $ rage -d -i key.txt -o data.tar.gz data.tar.gz.age + $ tar cvz ~/data | rage[EXE] -r age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p > data.tar.gz.age + $ rage[EXE] -d -i key.txt -o data.tar.gz data.tar.gz.age """ stderr = "" From 26a4a469e99815330800dc3325896513516432c8 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 16 Jan 2024 05:30:36 +0000 Subject: [PATCH 3/3] rage: Correctly handle extensions in the after-help text --- rage/src/bin/rage/cli.rs | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/rage/src/bin/rage/cli.rs b/rage/src/bin/rage/cli.rs index 60c061b2..477c1cb0 100644 --- a/rage/src/bin/rage/cli.rs +++ b/rage/src/bin/rage/cli.rs @@ -4,20 +4,32 @@ use clap::{builder::Styles, ArgAction, Parser}; use crate::fl; -fn binary_name() -> String { +fn binary_name(suffix: Option<&str>) -> String { if let Some(arg) = std::env::args_os().next() { - Path::new(&arg) - .file_name() - .expect("is not directory") - .to_string_lossy() - .to_string() + let path = Path::new(&arg); + if let Some(suffix) = suffix { + let stem = path + .file_stem() + .expect("is not directory") + .to_string_lossy(); + let extension = path + .extension() + .map(|extension| format!(".{}", extension.to_string_lossy())) + .unwrap_or_default(); + format!("{}{}{}", stem, suffix, extension) + } else { + path.file_name() + .expect("is not directory") + .to_string_lossy() + .to_string() + } } else { - "rage".into() + format!("rage{}", suffix.unwrap_or_default()) } } fn usage() -> String { - let binary_name = binary_name(); + let binary_name = binary_name(None); let recipient = fl!("recipient"); let identity = fl!("identity"); let input = fl!("input"); @@ -39,8 +51,8 @@ pub(crate) fn after_help_content(keygen_name: &str) -> String { } fn after_help() -> String { - let binary_name = binary_name(); - let keygen_name = format!("{}-keygen", binary_name); + let keygen_name = binary_name(Some("-keygen")); + let binary_name = binary_name(None); let example_a = format!("$ {} -o key.txt", keygen_name); let example_a_output = "age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p"; let example_b = format!(