Skip to content

Commit

Permalink
Merge pull request #442 from str4d/437-clap
Browse files Browse the repository at this point in the history
Migrate to `clap`, and localize usage & help text
  • Loading branch information
str4d authored Jan 10, 2024
2 parents 53972bd + b3de9b9 commit a1173d4
Show file tree
Hide file tree
Showing 24 changed files with 469 additions and 413 deletions.
46 changes: 23 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ rust-embed = "8"

# CLI
chrono = "0.4"
clap = { version = "4.3", features = ["derive"] }
console = { version = "0.15", default-features = false }
env_logger = "0.10"
gumdrop = "0.8"
log = "0.4"
2 changes: 1 addition & 1 deletion age-plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bech32.workspace = true
chrono.workspace = true

[dev-dependencies]
gumdrop.workspace = true
clap.workspace = true

[lib]
bench = false
14 changes: 6 additions & 8 deletions age-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ users will use identity files containing identities that specify that plugin nam

## Example plugin binary

The following example uses `gumdrop` to parse CLI arguments, but any argument parsing
The following example uses `clap` to parse CLI arguments, but any argument parsing
logic will work as long as it can detect the `--age-plugin=STATE_MACHINE` flag.

```rust
Expand All @@ -78,7 +78,8 @@ use age_plugin::{
recipient::{self, RecipientPluginV1},
Callbacks, run_state_machine,
};
use gumdrop::Options;
use clap::Parser;

use std::collections::HashMap;
use std::io;

Expand Down Expand Up @@ -133,17 +134,14 @@ impl IdentityPluginV1 for IdentityPlugin {
}
}

#[derive(Debug, Options)]
#[derive(Debug, Parser)]
struct PluginOptions {
#[options(help = "print help message")]
help: bool,

#[options(help = "run the given age plugin state machine", no_short)]
#[arg(help = "run the given age plugin state machine", long)]
age_plugin: Option<String>,
}

fn main() -> io::Result<()> {
let opts = PluginOptions::parse_args_default_or_exit();
let opts = PluginOptions::parse();

if let Some(state_machine) = opts.age_plugin {
// The plugin was started by an age client; run the state machine.
Expand Down
11 changes: 4 additions & 7 deletions age-plugin/examples/age-plugin-unencrypted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use age_plugin::{
recipient::{self, RecipientPluginV1},
run_state_machine, Callbacks,
};
use gumdrop::Options;
use clap::Parser;

use std::collections::HashMap;
use std::env;
Expand Down Expand Up @@ -139,17 +139,14 @@ impl IdentityPluginV1 for IdentityPlugin {
}
}

#[derive(Debug, Options)]
#[derive(Debug, Parser)]
struct PluginOptions {
#[options(help = "print help message")]
help: bool,

#[options(help = "run the given age plugin state machine", no_short)]
#[arg(help = "run the given age plugin state machine", long)]
age_plugin: Option<String>,
}

fn main() -> io::Result<()> {
let opts = PluginOptions::parse_args_default_or_exit();
let opts = PluginOptions::parse();

if let Some(state_machine) = opts.age_plugin {
run_state_machine(
Expand Down
14 changes: 6 additions & 8 deletions age-plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
//!
//! # Example plugin binary
//!
//! The following example uses `gumdrop` to parse CLI arguments, but any argument parsing
//! The following example uses `clap` to parse CLI arguments, but any argument parsing
//! logic will work as long as it can detect the `--age-plugin=STATE_MACHINE` flag.
//!
//! ```
Expand All @@ -76,7 +76,8 @@
//! recipient::{self, RecipientPluginV1},
//! Callbacks, run_state_machine,
//! };
//! use gumdrop::Options;
//! use clap::Parser;
//!
//! use std::collections::HashMap;
//! use std::io;
//!
Expand Down Expand Up @@ -131,17 +132,14 @@
//! }
//! }
//!
//! #[derive(Debug, Options)]
//! #[derive(Debug, Parser)]
//! struct PluginOptions {
//! #[options(help = "print help message")]
//! help: bool,
//!
//! #[options(help = "run the given age plugin state machine", no_short)]
//! #[arg(help = "run the given age plugin state machine", long)]
//! age_plugin: Option<String>,
//! }
//!
//! fn main() -> io::Result<()> {
//! let opts = PluginOptions::parse_args_default_or_exit();
//! let opts = PluginOptions::parse();
//!
//! if let Some(state_machine) = opts.age_plugin {
//! // The plugin was started by an age client; run the state machine.
Expand Down
1 change: 1 addition & 0 deletions rage/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ to 1.0.0 are beta releases.
## [Unreleased]
### Changed
- MSRV is now 1.65.0.
- Migrated from `gumdrop` to `clap` for argument parsing.

### Fixed
- OpenSSH private keys passed to `-i/--identity` that contain invalid public
Expand Down
3 changes: 1 addition & 2 deletions rage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ maintenance = { status = "experimental" }
# rage and rage-keygen dependencies
age = { workspace = true, features = ["armor", "cli-common", "plugin"] }
chrono.workspace = true
clap = { workspace = true, features = ["string", "unstable-styles"] }
console.workspace = true
env_logger.workspace = true
gumdrop.workspace = true
i18n-embed = { workspace = true, features = ["desktop-requester"] }
i18n-embed-fl.workspace = true
lazy_static.workspace = true
Expand All @@ -76,7 +76,6 @@ time = { version = ">=0.3.7, <0.3.24", optional = true } # time 0.3.24 has MSRV
zip = { version = "0.6.2", optional = true }

[dev-dependencies]
clap = { version = "4", default-features = false }
clap_complete = "4"
flate2 = "1"
man = "0.3"
Expand Down
55 changes: 40 additions & 15 deletions rage/i18n/en-US/rage.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Localization for strings in the rage CLI tools

-age = age
-age-plugin- = age-plugin-
-rage = rage
## CLI flags
Expand All @@ -27,31 +28,45 @@
## Usage

-input = INPUT
-output = OUTPUT
-identity = IDENTITY
-recipient = RECIPIENT
-recipients-file = PATH
usage-header = Usage
usage-header = Usage:
recipient = RECIPIENT
recipients-file = PATH
identity = IDENTITY
plugin-name = PLUGIN-NAME
input = INPUT
output = OUTPUT
rage-usage =
{usage-header}
{" "}{$usage_a}
{" "}{$usage_b}
args-header = Arguments
{$flags}
help-arg-input = Path to a file to read from.
{-input} defaults to standard input, and {-output} defaults to standard output.
flags-header = Options
{-recipient} can be:
help-flag-help = Print this help message and exit.
help-flag-version = Print version info and exit.
help-flag-encrypt = Encrypt the input (the default).
help-flag-decrypt = Decrypt the input.
help-flag-passphrase = Encrypt with a passphrase instead of recipients.
help-flag-max-work-factor = Maximum work factor to allow for passphrase decryption.
help-flag-armor = Encrypt to a PEM encoded format.
help-flag-recipient = Encrypt to the specified {recipient}. May be repeated.
help-flag-recipients-file = Encrypt to the recipients listed at {recipients-file}. May be repeated.
help-flag-identity = Use the identity file at {identity}. May be repeated.
help-flag-plugin-name = Use {-age-plugin-}{plugin-name} in its default mode as an identity.
help-flag-output = Write the result to the file at path {output}.
rage-after-help =
{input} defaults to standard input, and {output} defaults to standard output.
{recipient} can be:
- An {-age} public key, as generated by {$keygen_name} ("age1...").
- An SSH public key ("ssh-ed25519 AAAA...", "ssh-rsa AAAA...").
{-recipients-file} is a path to a file containing {-age} recipients, one per line
{recipients-file} is a path to a file containing {-age} recipients, one per line
(ignoring "#" prefixed comments and empty lines).
{-identity} is a path to a file with {-age} identities, one per line
{identity} is a path to a file with {-age} identities, one per line
(ignoring "#" prefixed comments and empty lines), or to an SSH key file.
Passphrase-encrypted {-age} identity files can be used as identity files.
Multiple identities may be provided, and any unused ones will be ignored.
Expand All @@ -62,6 +77,8 @@ rage-usage =
{" "}{$example_b}
{" "}{$example_c}
keygen-help-flag-output = {help-flag-output} Defaults to standard output.
## Formatting

warning-msg = Warning: {$warning}
Expand Down Expand Up @@ -161,6 +178,14 @@ rec-dec-recipient-flag = Did you mean to use {-flag-identity} to specify a priva

-flag-mnt-types = -t/--types
mnt-filename = FILENAME
mnt-mountpoint = MOUNTPOINT
mnt-types = TYPES
help-arg-mnt-filename = The encrypted filesystem to mount.
help-arg-mnt-mountpoint = The directory to mount the filesystem at.
help-arg-mnt-types = Indicates the filesystem type (one of {$types}).
info-decrypting = Decrypting {$filename}
info-mounting-as-fuse = Mounting as FUSE filesystem
Expand Down
Loading

0 comments on commit a1173d4

Please sign in to comment.