mirror of
https://github.com/chmln/sd
synced 2024-11-22 19:23:08 +00:00
Default to regex mode
This commit is contained in:
parent
67afb2628a
commit
162cd3fd86
2 changed files with 8 additions and 8 deletions
15
src/app.rs
15
src/app.rs
|
@ -3,6 +3,7 @@ use structopt::StructOpt;
|
|||
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(
|
||||
// hide author from help
|
||||
author = "",
|
||||
raw(setting = "structopt::clap::AppSettings::ColoredHelp"),
|
||||
raw(setting = "structopt::clap::AppSettings::NextLineHelp")
|
||||
|
@ -12,15 +13,15 @@ pub(crate) struct Options {
|
|||
#[structopt(short = "i", long = "input")]
|
||||
file_path: Option<String>,
|
||||
|
||||
/// Enable regular expressions
|
||||
#[structopt(short = "r", long = "regex")]
|
||||
enable_regex: bool,
|
||||
/// Treat expressions as non-regex strings
|
||||
#[structopt(short = "s", long = "string-mode")]
|
||||
literal_mode: bool,
|
||||
|
||||
/// The string or regexp (if --regex) to search for.
|
||||
/// The regexp or string (if --literal) to search for.
|
||||
find: String,
|
||||
|
||||
/// What to replace each match with. If regex is enabled,
|
||||
/// you may use captured values like $1, $2, etc.
|
||||
/// What to replace each match with. Unless in string mode, you may
|
||||
/// use captured values like $1, $2, etc.
|
||||
replace_with: String,
|
||||
}
|
||||
|
||||
|
@ -28,7 +29,7 @@ pub(crate) fn run() -> Result<(), Error> {
|
|||
let args = Options::from_args();
|
||||
let source = Source::from(args.file_path);
|
||||
let mut stream: Stream = (&source).into_stream()?;
|
||||
stream.replace(args.enable_regex, &args.find, &args.replace_with)?;
|
||||
stream.replace(!args.literal_mode, &args.find, &args.replace_with)?;
|
||||
|
||||
// replace file in-place, or pipe to stdout
|
||||
stream.output(&source)
|
||||
|
|
|
@ -21,7 +21,6 @@ impl Source {
|
|||
let mut buffer = String::new();
|
||||
let stdin = std::io::stdin();
|
||||
let mut handle = stdin.lock();
|
||||
|
||||
handle.read_to_string(&mut buffer)?;
|
||||
Ok(Stream::new(buffer))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue