parent
146c0697f2
commit
1a6dfb8d46
2 changed files with 13 additions and 2 deletions
|
@ -41,6 +41,9 @@ pub struct Args {
|
|||
#[clap(short = 'o', long)]
|
||||
pub output: Option<PathBuf>,
|
||||
|
||||
#[clap(long)]
|
||||
pub dry_run: bool,
|
||||
|
||||
#[clap(value_parser)]
|
||||
pub sections: Vec<String>,
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
use crate::{cli::Args, domain};
|
||||
use std::fs::File;
|
||||
use std::io::{stdout, Write};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
|
@ -36,8 +37,15 @@ impl std::error::Error for Error {}
|
|||
|
||||
pub fn execute(args: &Args) -> Result<(), Error> {
|
||||
let content = std::fs::read_to_string(&args.file).map_err(|_| Error::OpenFile)?;
|
||||
let writer =
|
||||
File::create(args.output.as_ref().unwrap_or(&args.file)).map_err(|_| Error::OpenFile)?;
|
||||
|
||||
let writer: Box<dyn Write> = if args.dry_run {
|
||||
Box::new(stdout())
|
||||
} else {
|
||||
Box::new(
|
||||
File::create(args.output.as_ref().unwrap_or(&args.file))
|
||||
.map_err(|_| Error::OpenFile)?,
|
||||
)
|
||||
};
|
||||
|
||||
domain::switch::execute(domain::switch::Request {
|
||||
content: &content,
|
||||
|
|
Loading…
Reference in a new issue