Skip to content

Commit 8529414

Browse files
committed
chore: update CLI tool to use clap
The CLI is using structopt, which is kind of deprecated and replaced by clap. Hence use clap instead.
1 parent f035d95 commit 8529414

File tree

3 files changed

+34
-181
lines changed

3 files changed

+34
-181
lines changed

Cargo.lock

Lines changed: 22 additions & 169 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ edition = "2018"
99

1010
[dependencies]
1111
anyhow = "1.0"
12+
clap = { version = "4.5.0", features = ["derive"] }
1213
env_logger = "0.11"
1314
log = "0.4"
1415
multibase = { path = ".." }
15-
structopt = "0.3"
1616

1717
[[bin]]
1818
name = "multibase"

cli/main.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,38 @@ use std::io::{self, Read, Write};
33
use std::str::FromStr;
44

55
use anyhow::{anyhow, Error, Result};
6+
use clap::{Parser, Subcommand};
67
use multibase::Base;
7-
use structopt::StructOpt;
88

9-
#[derive(StructOpt, Debug)]
9+
#[derive(Parser, Debug)]
1010
struct Opts {
1111
/// The mode
12-
#[structopt(subcommand)]
12+
#[command(subcommand)]
1313
mode: Mode,
1414
}
1515

16-
#[derive(StructOpt, Debug)]
16+
#[derive(Subcommand, Debug)]
1717
enum Mode {
18-
#[structopt(name = "encode")]
18+
#[command(name = "encode")]
1919
Encode {
2020
/// The base to use for encoding.
21-
#[structopt(short = "b", long = "base", default_value = "base58btc")]
21+
#[arg(short = 'b', long = "base", default_value = "base58btc")]
2222
base: StrBase,
2323
/// The data to encode. Reads from stdin if not provided.
24-
#[structopt(short = "i", long = "input")]
24+
#[arg(short = 'i', long = "input")]
2525
input: Option<String>,
2626
},
27-
#[structopt(name = "decode")]
27+
#[command(name = "decode")]
2828
Decode {
2929
/// The data to decode. Reads from stdin if not provided.
30-
#[structopt(short = "i", long = "input")]
30+
#[arg(short = 'i', long = "input")]
3131
input: Option<String>,
3232
},
3333
}
3434

3535
fn main() -> Result<()> {
3636
env_logger::init();
37-
let opts = Opts::from_args();
37+
let opts = Opts::parse();
3838
match opts.mode {
3939
Mode::Encode { base, input } => {
4040
let input_bytes = match input {
@@ -61,7 +61,7 @@ fn main() -> Result<()> {
6161
}
6262
}
6363

64-
#[derive(Debug)]
64+
#[derive(Debug, Clone)]
6565
struct StrBase(Base);
6666

6767
impl fmt::Display for StrBase {

0 commit comments

Comments
 (0)