Skip to content

Commit a75e007

Browse files
authored
Merge pull request #1007 from tamird/clap
examples: replace structopt with clap
2 parents 3da58f3 + 8c92f9f commit a75e007

15 files changed

+60
-60
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ openssl-sys = { version = "0.9.45", optional = true }
2727
openssl-probe = { version = "0.1", optional = true }
2828

2929
[dev-dependencies]
30-
structopt = "0.3"
30+
clap = { version = "4.4.13", features = ["derive"] }
3131
time = "0.1.39"
3232
tempfile = "3.1.0"
3333

examples/add.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
#![deny(warnings)]
1616
#![allow(trivial_casts)]
1717

18+
use clap::Parser;
1819
use git2::Repository;
1920
use std::path::Path;
20-
use structopt::StructOpt;
2121

22-
#[derive(StructOpt)]
22+
#[derive(Parser)]
2323
struct Args {
2424
#[structopt(name = "spec")]
2525
arg_spec: Vec<String>,
26-
#[structopt(name = "dry_run", short = "n", long)]
26+
#[structopt(name = "dry_run", short = 'n', long)]
2727
/// dry run
2828
flag_dry_run: bool,
2929
#[structopt(name = "verbose", short, long)]
@@ -73,7 +73,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
7373
}
7474

7575
fn main() {
76-
let args = Args::from_args();
76+
let args = Args::parse();
7777
match run(&args) {
7878
Ok(()) => {}
7979
Err(e) => println!("error: {}", e),

examples/blame.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@
1414

1515
#![deny(warnings)]
1616

17+
use clap::Parser;
1718
use git2::{BlameOptions, Repository};
1819
use std::io::{BufRead, BufReader};
1920
use std::path::Path;
20-
use structopt::StructOpt;
2121

22-
#[derive(StructOpt)]
22+
#[derive(Parser)]
2323
#[allow(non_snake_case)]
2424
struct Args {
2525
#[structopt(name = "path")]
2626
arg_path: String,
2727
#[structopt(name = "spec")]
2828
arg_spec: Option<String>,
29-
#[structopt(short = "M")]
29+
#[structopt(short = 'M')]
3030
/// find line moves within and across files
3131
flag_M: bool,
32-
#[structopt(short = "C")]
32+
#[structopt(short = 'C')]
3333
/// find line copies within and across files
3434
flag_C: bool,
35-
#[structopt(short = "F")]
35+
#[structopt(short = 'F')]
3636
/// follow only the first parent commits
3737
flag_F: bool,
3838
}
@@ -96,7 +96,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
9696
}
9797

9898
fn main() {
99-
let args = Args::from_args();
99+
let args = Args::parse();
100100
match run(&args) {
101101
Ok(()) => {}
102102
Err(e) => println!("error: {}", e),

examples/cat-file.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@
1616

1717
use std::io::{self, Write};
1818

19+
use clap::Parser;
1920
use git2::{Blob, Commit, ObjectType, Repository, Signature, Tag, Tree};
20-
use structopt::StructOpt;
2121

22-
#[derive(StructOpt)]
22+
#[derive(Parser)]
2323
struct Args {
2424
#[structopt(name = "object")]
2525
arg_object: String,
26-
#[structopt(short = "t")]
26+
#[structopt(short = 't')]
2727
/// show the object type
2828
flag_t: bool,
29-
#[structopt(short = "s")]
29+
#[structopt(short = 's')]
3030
/// show the object size
3131
flag_s: bool,
32-
#[structopt(short = "e")]
32+
#[structopt(short = 'e')]
3333
/// suppress all output
3434
flag_e: bool,
35-
#[structopt(short = "p")]
35+
#[structopt(short = 'p')]
3636
/// pretty print the contents of the object
3737
flag_p: bool,
3838
#[structopt(name = "quiet", short, long)]
@@ -141,7 +141,7 @@ fn show_sig(header: &str, sig: Option<Signature>) {
141141
}
142142

143143
fn main() {
144-
let args = Args::from_args();
144+
let args = Args::parse();
145145
match run(&args) {
146146
Ok(()) => {}
147147
Err(e) => println!("error: {}", e),

examples/clone.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414

1515
#![deny(warnings)]
1616

17+
use clap::Parser;
1718
use git2::build::{CheckoutBuilder, RepoBuilder};
1819
use git2::{FetchOptions, Progress, RemoteCallbacks};
1920
use std::cell::RefCell;
2021
use std::io::{self, Write};
2122
use std::path::{Path, PathBuf};
22-
use structopt::StructOpt;
2323

24-
#[derive(StructOpt)]
24+
#[derive(Parser)]
2525
struct Args {
2626
#[structopt(name = "url")]
2727
arg_url: String,
@@ -118,7 +118,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
118118
}
119119

120120
fn main() {
121-
let args = Args::from_args();
121+
let args = Args::parse();
122122
match run(&args) {
123123
Ok(()) => {}
124124
Err(e) => println!("error: {}", e),

examples/diff.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
#![deny(warnings)]
1616

17+
use clap::Parser;
1718
use git2::{Blob, Diff, DiffOptions, Error, Object, ObjectType, Oid, Repository};
1819
use git2::{DiffDelta, DiffFindOptions, DiffFormat, DiffHunk, DiffLine};
1920
use std::str;
20-
use structopt::StructOpt;
2121

22-
#[derive(StructOpt)]
22+
#[derive(Parser)]
2323
#[allow(non_snake_case)]
2424
struct Args {
2525
#[structopt(name = "from_oid")]
@@ -56,19 +56,19 @@ struct Args {
5656
#[structopt(name = "no-color", long)]
5757
/// never use color output
5858
flag_no_color: bool,
59-
#[structopt(short = "R")]
59+
#[structopt(short = 'R')]
6060
/// swap two inputs
6161
flag_R: bool,
62-
#[structopt(name = "text", short = "a", long)]
62+
#[structopt(name = "text", short = 'a', long)]
6363
/// treat all files as text
6464
flag_text: bool,
6565
#[structopt(name = "ignore-space-at-eol", long)]
6666
/// ignore changes in whitespace at EOL
6767
flag_ignore_space_at_eol: bool,
68-
#[structopt(name = "ignore-space-change", short = "b", long)]
68+
#[structopt(name = "ignore-space-change", short = 'b', long)]
6969
/// ignore changes in amount of whitespace
7070
flag_ignore_space_change: bool,
71-
#[structopt(name = "ignore-all-space", short = "w", long)]
71+
#[structopt(name = "ignore-all-space", short = 'w', long)]
7272
/// ignore whitespace when comparing lines
7373
flag_ignore_all_space: bool,
7474
#[structopt(name = "ignored", long)]
@@ -95,19 +95,19 @@ struct Args {
9595
#[structopt(name = "summary", long)]
9696
/// output condensed summary of header info
9797
flag_summary: bool,
98-
#[structopt(name = "find-renames", short = "M", long)]
98+
#[structopt(name = "find-renames", short = 'M', long)]
9999
/// set threshold for finding renames (default 50)
100100
flag_find_renames: Option<u16>,
101-
#[structopt(name = "find-copies", short = "C", long)]
101+
#[structopt(name = "find-copies", short = 'C', long)]
102102
/// set threshold for finding copies (default 50)
103103
flag_find_copies: Option<u16>,
104104
#[structopt(name = "find-copies-harder", long)]
105105
/// inspect unmodified files for sources of copies
106106
flag_find_copies_harder: bool,
107-
#[structopt(name = "break_rewrites", short = "B", long)]
107+
#[structopt(name = "break_rewrites", short = 'B', long)]
108108
/// break complete rewrite changes into pairs
109109
flag_break_rewrites: bool,
110-
#[structopt(name = "unified", short = "U", long)]
110+
#[structopt(name = "unified", short = 'U', long)]
111111
/// lints of context to show
112112
flag_unified: Option<u32>,
113113
#[structopt(name = "inter-hunk-context", long)]
@@ -360,7 +360,7 @@ impl Args {
360360
}
361361

362362
fn main() {
363-
let args = Args::from_args();
363+
let args = Args::parse();
364364
match run(&args) {
365365
Ok(()) => {}
366366
Err(e) => println!("error: {}", e),

examples/fetch.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
#![deny(warnings)]
1616

17+
use clap::Parser;
1718
use git2::{AutotagOption, FetchOptions, RemoteCallbacks, Repository};
1819
use std::io::{self, Write};
1920
use std::str;
20-
use structopt::StructOpt;
2121

22-
#[derive(StructOpt)]
22+
#[derive(Parser)]
2323
struct Args {
2424
#[structopt(name = "remote")]
2525
arg_remote: Option<String>,
@@ -119,7 +119,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
119119
}
120120

121121
fn main() {
122-
let args = Args::from_args();
122+
let args = Args::parse();
123123
match run(&args) {
124124
Ok(()) => {}
125125
Err(e) => println!("error: {}", e),

examples/init.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
#![deny(warnings)]
1616

17+
use clap::Parser;
1718
use git2::{Error, Repository, RepositoryInitMode, RepositoryInitOptions};
1819
use std::path::{Path, PathBuf};
19-
use structopt::StructOpt;
2020

21-
#[derive(StructOpt)]
21+
#[derive(Parser)]
2222
struct Args {
2323
#[structopt(name = "directory")]
2424
arg_directory: String,
@@ -137,7 +137,7 @@ fn parse_shared(shared: &str) -> Result<RepositoryInitMode, Error> {
137137
}
138138

139139
fn main() {
140-
let args = Args::from_args();
140+
let args = Args::parse();
141141
match run(&args) {
142142
Ok(()) => {}
143143
Err(e) => println!("error: {}", e),

examples/log.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
#![deny(warnings)]
1616

17+
use clap::Parser;
1718
use git2::{Commit, DiffOptions, ObjectType, Repository, Signature, Time};
1819
use git2::{DiffFormat, Error, Pathspec};
1920
use std::str;
20-
use structopt::StructOpt;
2121

22-
#[derive(StructOpt)]
22+
#[derive(Parser)]
2323
struct Args {
2424
#[structopt(name = "topo-order", long)]
2525
/// sort commits in topological order
@@ -45,7 +45,7 @@ struct Args {
4545
#[structopt(name = "skip", long)]
4646
/// number of commits to skip
4747
flag_skip: Option<usize>,
48-
#[structopt(name = "max-count", short = "n", long)]
48+
#[structopt(name = "max-count", short = 'n', long)]
4949
/// maximum number of commits to show
5050
flag_max_count: Option<usize>,
5151
#[structopt(name = "merges", long)]
@@ -302,7 +302,7 @@ impl Args {
302302
}
303303

304304
fn main() {
305-
let args = Args::from_args();
305+
let args = Args::parse();
306306
match run(&args) {
307307
Ok(()) => {}
308308
Err(e) => println!("error: {}", e),

examples/ls-remote.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
#![deny(warnings)]
1616

17+
use clap::Parser;
1718
use git2::{Direction, Repository};
18-
use structopt::StructOpt;
1919

20-
#[derive(StructOpt)]
20+
#[derive(Parser)]
2121
struct Args {
2222
#[structopt(name = "remote")]
2323
arg_remote: String,
@@ -43,7 +43,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
4343
}
4444

4545
fn main() {
46-
let args = Args::from_args();
46+
let args = Args::parse();
4747
match run(&args) {
4848
Ok(()) => {}
4949
Err(e) => println!("error: {}", e),

examples/pull.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
* <http://creativecommons.org/publicdomain/zero/1.0/>.
1313
*/
1414

15+
use clap::Parser;
1516
use git2::Repository;
1617
use std::io::{self, Write};
1718
use std::str;
18-
use structopt::StructOpt;
1919

20-
#[derive(StructOpt)]
20+
#[derive(Parser)]
2121
struct Args {
2222
arg_remote: Option<String>,
2323
arg_branch: Option<String>,
@@ -200,7 +200,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
200200
}
201201

202202
fn main() {
203-
let args = Args::from_args();
203+
let args = Args::parse();
204204
match run(&args) {
205205
Ok(()) => {}
206206
Err(e) => println!("error: {}", e),

examples/rev-list.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
#![deny(warnings)]
1717

18+
use clap::Parser;
1819
use git2::{Error, Oid, Repository, Revwalk};
19-
use structopt::StructOpt;
2020

21-
#[derive(StructOpt)]
21+
#[derive(Parser)]
2222
struct Args {
2323
#[structopt(name = "topo-order", long)]
2424
/// sort commits in topological order
@@ -97,7 +97,7 @@ fn push(revwalk: &mut Revwalk, id: Oid, hide: bool) -> Result<(), Error> {
9797
}
9898

9999
fn main() {
100-
let args = Args::from_args();
100+
let args = Args::parse();
101101
match run(&args) {
102102
Ok(()) => {}
103103
Err(e) => println!("error: {}", e),

examples/rev-parse.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
#![deny(warnings)]
1616

17+
use clap::Parser;
1718
use git2::Repository;
18-
use structopt::StructOpt;
1919

20-
#[derive(StructOpt)]
20+
#[derive(Parser)]
2121
struct Args {
2222
#[structopt(name = "spec")]
2323
arg_spec: String,
@@ -52,7 +52,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
5252
}
5353

5454
fn main() {
55-
let args = Args::from_args();
55+
let args = Args::parse();
5656
match run(&args) {
5757
Ok(()) => {}
5858
Err(e) => println!("error: {}", e),

0 commit comments

Comments
 (0)