mirror of
https://github.com/crate-ci/typos.git
synced 2025-02-13 08:40:29 -05:00
feat(config): Use '-' to dump config to stdout
This commit is contained in:
parent
13a93ee8d1
commit
dbac2eff4a
2 changed files with 6 additions and 2 deletions
|
@ -76,7 +76,7 @@ pub(crate) struct Args {
|
||||||
pub(crate) words: bool,
|
pub(crate) words: bool,
|
||||||
|
|
||||||
#[structopt(long, group = "mode")]
|
#[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>,
|
pub(crate) dump_config: Option<std::path::PathBuf>,
|
||||||
|
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
|
|
|
@ -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();
|
let mut defaulted_config = config::Config::from_defaults();
|
||||||
defaulted_config.update(&config);
|
defaulted_config.update(&config);
|
||||||
let output = toml::to_string_pretty(&defaulted_config).with_code(proc_exit::Code::FAILURE)?;
|
let output = toml::to_string_pretty(&defaulted_config).with_code(proc_exit::Code::FAILURE)?;
|
||||||
|
if output_path == std::path::Path::new("-") {
|
||||||
|
std::io::stdout().write_all(output.as_bytes())?;
|
||||||
|
} else {
|
||||||
std::fs::write(output_path, &output)?;
|
std::fs::write(output_path, &output)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue