diff --git a/src/cli.rs b/src/cli.rs index e236cf0..37be42d 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -41,6 +41,9 @@ pub struct Args { #[clap(short = 'o', long)] pub output: Option, + #[clap(long)] + pub dry_run: bool, + #[clap(value_parser)] pub sections: Vec, } diff --git a/src/cli/switch.rs b/src/cli/switch.rs index a73ab3c..ab3a2f3 100644 --- a/src/cli/switch.rs +++ b/src/cli/switch.rs @@ -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 = 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,