blob: 07c48b84a0a945acc5d786b1f77d498e065a4a8c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
mod cli;
mod error;
mod input;
pub(crate) mod replacer;
pub(crate) mod utils;
use std::process;
pub(crate) use self::input::{App, Source};
use ansi_term::{Color, Style};
pub(crate) use error::{Error, Result};
use replacer::Replacer;
use clap::Parser;
fn main() {
if let Err(e) = try_main() {
eprintln!("{}: {}", Style::from(Color::Red).bold().paint("error"), e);
process::exit(1);
}
}
fn try_main() -> Result<()> {
let options = cli::Options::parse();
let source = if !options.files.is_empty() {
Source::Files(options.files)
} else {
Source::Stdin
};
App::new(
source,
Replacer::new(
options.find,
options.replace_with,
options.literal_mode,
options.flags,
options.replacements,
)?,
)
.run(options.preview)?;
Ok(())
}
|