Skip to content

Commit

Permalink
replace structopt
Browse files Browse the repository at this point in the history
  • Loading branch information
untitaker committed Jun 25, 2023
1 parent 160be91 commit 9297afc
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 89 deletions.
149 changes: 70 additions & 79 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ readme = "README.md"
[dependencies]
thiserror = "1.0.22"
regex = "1.4.2"
structopt = "0.3.20"
anyhow = "1.0.34"
ignore = "0.4.16"
console = "0.13.0"
Expand All @@ -21,6 +20,10 @@ blake3 = "1.4.0"
rayon = "1.7.0"
similar = { version = "2.2.1", features = ["text"] }

# Disable clap's suggestions feature, because it sometimes suggests nonsense:
# https://github.com/clap-rs/clap/discussions/3962
clap = { version = "3.2.8", features = ["std", "derive", "color"], default-features = false }

[dev-dependencies]
# https://github.com/mitsuhiko/insta-cmd/issues/7
insta = "=1.18.0"
Expand Down
18 changes: 9 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use std::path::{Path, PathBuf};
use std::sync::mpsc::sync_channel;

use anyhow::{Context, Error};
use clap::Parser;
use console::{style, Key, Style};
use ignore::WalkState;
use itertools::Itertools;
use similar::{ChangeTag, TextDiff};
use structopt::StructOpt;

use expr::{parse_pairs, Expr, Replacer};

#[derive(StructOpt)]
#[derive(Parser)]
#[structopt(name = "spacemod")]
struct Cli {
/// The pattern to search for.
Expand All @@ -30,37 +30,37 @@ struct Cli {
file_or_dir: Vec<PathBuf>,

/// How many threads to use, default is to try and saturate CPU.
#[structopt(short = "j", long = "jobs")]
#[structopt(short = 'j', long = "jobs")]
threads: Option<usize>,

/// Enable replacing in hidden files.
#[structopt(short = "u", long = "hidden")]
#[structopt(short = 'u', long = "hidden")]
hidden: bool,

/// Enable parenthesis-matching and implicit whitespace matching.
///
/// Any (unescaped) space in SEARCH is implicitly replaced with '\s*', and parenthesis
/// surrounded by spaces such as in '( .* )' will match literally.
#[structopt(short = "S", long = "spacemode")]
#[structopt(short = 'S', long = "spacemode")]
spacemode: bool,

/// Interpret SEARCH as literal string.
///
/// Disables all pattern-matching.
#[structopt(short = "F", long = "fixed-strings")]
#[structopt(short = 'F', long = "fixed-strings")]
fixed_strings: bool,

/// Have regex work over multiple lines.
///
/// When using parenthesis-matching, multiline mode is already enabled.
#[structopt(short = "m", long = "multiline")]
#[structopt(short = 'm', long = "multiline")]
multiline: bool,
/// Automatically accept all changes (use with caution).
#[structopt(long = "accept-all")]
accept_all: bool,
/// A list of file extensions to process. Either comma-delimited or by passing the option
/// multiple times.
#[structopt(short = "e", long = "extensions", use_delimiter(true))]
#[structopt(short = 'e', long = "extensions", use_delimiter(true))]
extensions: Vec<String>,
/// A set of parenthesis to support in addition to the defaults. This option is necessary for
/// spacemod to understand that ')' is the counterpart to '(', for example.
Expand All @@ -77,7 +77,7 @@ struct Cli {
///
/// Specifying this option will append to that list. The option can be specified multiple
/// times.
#[structopt(short = "p", long = "pairs")]
#[structopt(short = 'p', long = "pairs")]
pairs: Vec<String>,
}

Expand Down

0 comments on commit 9297afc

Please sign in to comment.