Skip to content

Commit

Permalink
examples: replace structopt with clap
Browse files Browse the repository at this point in the history
See TeXitoi/structopt#525.

Currently git2 is the second most downloaded dependent of structopt:
https://crates.io/crates/structopt/reverse_dependencies.
  • Loading branch information
tamird committed Jan 11, 2024
1 parent af35029 commit cccdde2
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ openssl-sys = { version = "0.9.45", optional = true }
openssl-probe = { version = "0.1", optional = true }

[dev-dependencies]
structopt = "0.3"
clap = { version = "4.4.13", features = ["derive"] }
time = "0.1.39"
tempfile = "3.1.0"

Expand Down
8 changes: 4 additions & 4 deletions examples/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
#![deny(warnings)]
#![allow(trivial_casts)]

use clap::Parser;
use git2::Repository;
use std::path::Path;
use structopt::StructOpt;

#[derive(StructOpt)]
#[derive(Parser)]
struct Args {
#[structopt(name = "spec")]
arg_spec: Vec<String>,
#[structopt(name = "dry_run", short = "n", long)]
#[structopt(name = "dry_run", short = 'n', long)]
/// dry run
flag_dry_run: bool,
#[structopt(name = "verbose", short, long)]
Expand Down Expand Up @@ -73,7 +73,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
}

fn main() {
let args = Args::from_args();
let args = Args::parse();
match run(&args) {
Ok(()) => {}
Err(e) => println!("error: {}", e),
Expand Down
12 changes: 6 additions & 6 deletions examples/blame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@

#![deny(warnings)]

use clap::Parser;
use git2::{BlameOptions, Repository};
use std::io::{BufRead, BufReader};
use std::path::Path;
use structopt::StructOpt;

#[derive(StructOpt)]
#[derive(Parser)]
#[allow(non_snake_case)]
struct Args {
#[structopt(name = "path")]
arg_path: String,
#[structopt(name = "spec")]
arg_spec: Option<String>,
#[structopt(short = "M")]
#[structopt(short = 'M')]
/// find line moves within and across files
flag_M: bool,
#[structopt(short = "C")]
#[structopt(short = 'C')]
/// find line copies within and across files
flag_C: bool,
#[structopt(short = "F")]
#[structopt(short = 'F')]
/// follow only the first parent commits
flag_F: bool,
}
Expand Down Expand Up @@ -96,7 +96,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
}

fn main() {
let args = Args::from_args();
let args = Args::parse();
match run(&args) {
Ok(()) => {}
Err(e) => println!("error: {}", e),
Expand Down
14 changes: 7 additions & 7 deletions examples/cat-file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@

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

use clap::Parser;
use git2::{Blob, Commit, ObjectType, Repository, Signature, Tag, Tree};
use structopt::StructOpt;

#[derive(StructOpt)]
#[derive(Parser)]
struct Args {
#[structopt(name = "object")]
arg_object: String,
#[structopt(short = "t")]
#[structopt(short = 't')]
/// show the object type
flag_t: bool,
#[structopt(short = "s")]
#[structopt(short = 's')]
/// show the object size
flag_s: bool,
#[structopt(short = "e")]
#[structopt(short = 'e')]
/// suppress all output
flag_e: bool,
#[structopt(short = "p")]
#[structopt(short = 'p')]
/// pretty print the contents of the object
flag_p: bool,
#[structopt(name = "quiet", short, long)]
Expand Down Expand Up @@ -141,7 +141,7 @@ fn show_sig(header: &str, sig: Option<Signature>) {
}

fn main() {
let args = Args::from_args();
let args = Args::parse();
match run(&args) {
Ok(()) => {}
Err(e) => println!("error: {}", e),
Expand Down
6 changes: 3 additions & 3 deletions examples/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

#![deny(warnings)]

use clap::Parser;
use git2::build::{CheckoutBuilder, RepoBuilder};
use git2::{FetchOptions, Progress, RemoteCallbacks};
use std::cell::RefCell;
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use structopt::StructOpt;

#[derive(StructOpt)]
#[derive(Parser)]
struct Args {
#[structopt(name = "url")]
arg_url: String,
Expand Down Expand Up @@ -118,7 +118,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
}

fn main() {
let args = Args::from_args();
let args = Args::parse();
match run(&args) {
Ok(()) => {}
Err(e) => println!("error: {}", e),
Expand Down
22 changes: 11 additions & 11 deletions examples/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

#![deny(warnings)]

use clap::Parser;
use git2::{Blob, Diff, DiffOptions, Error, Object, ObjectType, Oid, Repository};
use git2::{DiffDelta, DiffFindOptions, DiffFormat, DiffHunk, DiffLine};
use std::str;
use structopt::StructOpt;

#[derive(StructOpt)]
#[derive(Parser)]
#[allow(non_snake_case)]
struct Args {
#[structopt(name = "from_oid")]
Expand Down Expand Up @@ -56,19 +56,19 @@ struct Args {
#[structopt(name = "no-color", long)]
/// never use color output
flag_no_color: bool,
#[structopt(short = "R")]
#[structopt(short = 'R')]
/// swap two inputs
flag_R: bool,
#[structopt(name = "text", short = "a", long)]
#[structopt(name = "text", short = 'a', long)]
/// treat all files as text
flag_text: bool,
#[structopt(name = "ignore-space-at-eol", long)]
/// ignore changes in whitespace at EOL
flag_ignore_space_at_eol: bool,
#[structopt(name = "ignore-space-change", short = "b", long)]
#[structopt(name = "ignore-space-change", short = 'b', long)]
/// ignore changes in amount of whitespace
flag_ignore_space_change: bool,
#[structopt(name = "ignore-all-space", short = "w", long)]
#[structopt(name = "ignore-all-space", short = 'w', long)]
/// ignore whitespace when comparing lines
flag_ignore_all_space: bool,
#[structopt(name = "ignored", long)]
Expand All @@ -95,19 +95,19 @@ struct Args {
#[structopt(name = "summary", long)]
/// output condensed summary of header info
flag_summary: bool,
#[structopt(name = "find-renames", short = "M", long)]
#[structopt(name = "find-renames", short = 'M', long)]
/// set threshold for finding renames (default 50)
flag_find_renames: Option<u16>,
#[structopt(name = "find-copies", short = "C", long)]
#[structopt(name = "find-copies", short = 'C', long)]
/// set threshold for finding copies (default 50)
flag_find_copies: Option<u16>,
#[structopt(name = "find-copies-harder", long)]
/// inspect unmodified files for sources of copies
flag_find_copies_harder: bool,
#[structopt(name = "break_rewrites", short = "B", long)]
#[structopt(name = "break_rewrites", short = 'B', long)]
/// break complete rewrite changes into pairs
flag_break_rewrites: bool,
#[structopt(name = "unified", short = "U", long)]
#[structopt(name = "unified", short = 'U', long)]
/// lints of context to show
flag_unified: Option<u32>,
#[structopt(name = "inter-hunk-context", long)]
Expand Down Expand Up @@ -360,7 +360,7 @@ impl Args {
}

fn main() {
let args = Args::from_args();
let args = Args::parse();
match run(&args) {
Ok(()) => {}
Err(e) => println!("error: {}", e),
Expand Down
6 changes: 3 additions & 3 deletions examples/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

#![deny(warnings)]

use clap::Parser;
use git2::{AutotagOption, FetchOptions, RemoteCallbacks, Repository};
use std::io::{self, Write};
use std::str;
use structopt::StructOpt;

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

fn main() {
let args = Args::from_args();
let args = Args::parse();
match run(&args) {
Ok(()) => {}
Err(e) => println!("error: {}", e),
Expand Down
6 changes: 3 additions & 3 deletions examples/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

#![deny(warnings)]

use clap::Parser;
use git2::{Error, Repository, RepositoryInitMode, RepositoryInitOptions};
use std::path::{Path, PathBuf};
use structopt::StructOpt;

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

fn main() {
let args = Args::from_args();
let args = Args::parse();
match run(&args) {
Ok(()) => {}
Err(e) => println!("error: {}", e),
Expand Down
8 changes: 4 additions & 4 deletions examples/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

#![deny(warnings)]

use clap::Parser;
use git2::{Commit, DiffOptions, ObjectType, Repository, Signature, Time};
use git2::{DiffFormat, Error, Pathspec};
use std::str;
use structopt::StructOpt;

#[derive(StructOpt)]
#[derive(Parser)]
struct Args {
#[structopt(name = "topo-order", long)]
/// sort commits in topological order
Expand All @@ -45,7 +45,7 @@ struct Args {
#[structopt(name = "skip", long)]
/// number of commits to skip
flag_skip: Option<usize>,
#[structopt(name = "max-count", short = "n", long)]
#[structopt(name = "max-count", short = 'n', long)]
/// maximum number of commits to show
flag_max_count: Option<usize>,
#[structopt(name = "merges", long)]
Expand Down Expand Up @@ -302,7 +302,7 @@ impl Args {
}

fn main() {
let args = Args::from_args();
let args = Args::parse();
match run(&args) {
Ok(()) => {}
Err(e) => println!("error: {}", e),
Expand Down
6 changes: 3 additions & 3 deletions examples/ls-remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

#![deny(warnings)]

use clap::Parser;
use git2::{Direction, Repository};
use structopt::StructOpt;

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

fn main() {
let args = Args::from_args();
let args = Args::parse();
match run(&args) {
Ok(()) => {}
Err(e) => println!("error: {}", e),
Expand Down
6 changes: 3 additions & 3 deletions examples/pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/

use clap::Parser;
use git2::Repository;
use std::io::{self, Write};
use std::str;
use structopt::StructOpt;

#[derive(StructOpt)]
#[derive(Parser)]
struct Args {
arg_remote: Option<String>,
arg_branch: Option<String>,
Expand Down Expand Up @@ -200,7 +200,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
}

fn main() {
let args = Args::from_args();
let args = Args::parse();
match run(&args) {
Ok(()) => {}
Err(e) => println!("error: {}", e),
Expand Down
6 changes: 3 additions & 3 deletions examples/rev-list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

#![deny(warnings)]

use clap::Parser;
use git2::{Error, Oid, Repository, Revwalk};
use structopt::StructOpt;

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

fn main() {
let args = Args::from_args();
let args = Args::parse();
match run(&args) {
Ok(()) => {}
Err(e) => println!("error: {}", e),
Expand Down
6 changes: 3 additions & 3 deletions examples/rev-parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

#![deny(warnings)]

use clap::Parser;
use git2::Repository;
use structopt::StructOpt;

#[derive(StructOpt)]
#[derive(Parser)]
struct Args {
#[structopt(name = "spec")]
arg_spec: String,
Expand Down Expand Up @@ -52,7 +52,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
}

fn main() {
let args = Args::from_args();
let args = Args::parse();
match run(&args) {
Ok(()) => {}
Err(e) => println!("error: {}", e),
Expand Down
Loading

0 comments on commit cccdde2

Please sign in to comment.