Skip to content

Commit

Permalink
Migrate from gumdrop to clap
Browse files Browse the repository at this point in the history
Closes #437.
  • Loading branch information
str4d committed Jan 8, 2024
1 parent 50cb0a5 commit f9087be
Show file tree
Hide file tree
Showing 24 changed files with 333 additions and 365 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
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
8 changes: 1 addition & 7 deletions rage/i18n/en-US/rage.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@
usage-header = Usage:
rage-usage =
{usage-header}
{" "}{$usage_a}
{" "}{$usage_b}
{$flags}
rage-after-help =
{-input} defaults to standard input, and {-output} defaults to standard output.
{-recipient} can be:
Expand Down
8 changes: 1 addition & 7 deletions rage/i18n/es-AR/rage.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@
usage-header = Usage:
rage-usage =
{usage-header}
{" "}{$usage_a}
{" "}{$usage_b}
{$flags}
rage-after-help =
{-input} por defecto a standard input, y {-output} por defecto standard output.
{-recipient} puede ser:
Expand Down
8 changes: 1 addition & 7 deletions rage/i18n/it/rage.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@
usage-header = Usage:
rage-usage =
{usage-header}
{" "}{$usage_a}
{" "}{$usage_b}
{$flags}
rage-after-help =
{-input} ha come valore predefinito lo standard input, e {-output} ha come
valore predefinito lo standard output.
Expand Down
8 changes: 1 addition & 7 deletions rage/i18n/zh-CN/rage.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@
usage-header = Usage:
rage-usage =
{usage-header}
{" "}{$usage_a}
{" "}{$usage_b}
{$flags}
rage-after-help =
{-input} 默认为标准输入 (stdin), 而 {-output} 默认为标准输出 (stdout) 。
{-recipient} 可为:
Expand Down
8 changes: 1 addition & 7 deletions rage/i18n/zh-TW/rage.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@
usage-header = Usage:
rage-usage =
{usage-header}
{" "}{$usage_a}
{" "}{$usage_b}
{$flags}
rage-after-help =
{-input} 默認為標準輸入 (stdin), 而 {-output} 默認為標準輸出 (stdout) 。
{-recipient} 可為:
Expand Down
Loading

0 comments on commit f9087be

Please sign in to comment.