feat(config): Use '-' to dump config to stdout

This commit is contained in:
Ed Page 2021-01-04 19:15:05 -06:00
parent 13a93ee8d1
commit dbac2eff4a
2 changed files with 6 additions and 2 deletions

View file

@ -76,7 +76,7 @@ pub(crate) struct Args {
pub(crate) words: bool,
#[structopt(long, group = "mode")]
/// Write the current configuration to file.
/// Write the current configuration to file with `-` for stdout
pub(crate) dump_config: Option<std::path::PathBuf>,
#[structopt(flatten)]

View file

@ -63,7 +63,11 @@ fn run_dump_config(args: &args::Args, output_path: &std::path::Path) -> proc_exi
let mut defaulted_config = config::Config::from_defaults();
defaulted_config.update(&config);
let output = toml::to_string_pretty(&defaulted_config).with_code(proc_exit::Code::FAILURE)?;
std::fs::write(output_path, &output)?;
if output_path == std::path::Path::new("-") {
std::io::stdout().write_all(output.as_bytes())?;
} else {
std::fs::write(output_path, &output)?;
}
Ok(())
}