add output option

Closes #6
This commit is contained in:
Dmitriy Pleshevskiy 2022-07-29 19:02:17 +03:00
parent e94a9ca351
commit 4cd7087f13
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
2 changed files with 4 additions and 1 deletions

View file

@ -36,6 +36,9 @@ pub struct Args {
#[clap(short = 'f', long, default_value = ".env")] #[clap(short = 'f', long, default_value = ".env")]
pub file: PathBuf, pub file: PathBuf,
#[clap(short = 'o', long)]
pub output: Option<PathBuf>,
#[clap(value_parser)] #[clap(value_parser)]
pub section_names: Vec<String>, pub section_names: Vec<String>,
} }

View file

@ -35,7 +35,7 @@ fn main() -> Result<(), Error> {
fn change_env_layout(args: &cli::Args) -> 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 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_err(|_| Error::OpenFile)
.map(BufWriter::new)?; .map(BufWriter::new)?;