diff --git a/src/cli.rs b/src/cli.rs index 204150a..46d599f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -36,6 +36,9 @@ pub struct Args { #[clap(short = 'f', long, default_value = ".env")] pub file: PathBuf, + #[clap(short = 'o', long)] + pub output: Option, + #[clap(value_parser)] pub section_names: Vec, } diff --git a/src/main.rs b/src/main.rs index 0222476..a9029f6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,7 +35,7 @@ fn main() -> Result<(), Error> { fn change_env_layout(args: &cli::Args) -> Result<(), Error> { let content = std::fs::read_to_string(&args.file).map_err(|_| Error::OpenFile)?; - let mut writer = File::create(&args.file) + let mut writer = File::create(args.output.as_ref().unwrap_or(&args.file)) .map_err(|_| Error::OpenFile) .map(BufWriter::new)?;