Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit 979062d

Browse files
dklimpelsandhose
authored andcommitted
allow config dump to file
1 parent c2c1287 commit 979062d

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

crates/cli/src/commands/config.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,13 @@ pub(super) struct Options {
9090
#[derive(Parser, Debug)]
9191
enum Subcommand {
9292
/// Dump the current config as YAML
93-
Dump,
93+
Dump {
94+
/// The path to the config file to dump
95+
///
96+
/// If not specified, the config will be written to stdout
97+
#[clap(short, long)]
98+
output: Option<Utf8PathBuf>,
99+
},
94100

95101
/// Check a config file
96102
Check,
@@ -121,12 +127,20 @@ impl Options {
121127
pub async fn run(self, root: &super::Options) -> anyhow::Result<()> {
122128
use Subcommand as SC;
123129
match self.subcommand {
124-
SC::Dump => {
130+
SC::Dump { output } => {
125131
let _span = info_span!("cli.config.dump").entered();
126132

127133
let config: RootConfig = root.load_config()?;
134+
let config = serde_yaml::to_string(&config)?;
128135

129-
serde_yaml::to_writer(std::io::stdout(), &config)?;
136+
if let Some(output) = output {
137+
info!("Writing configuration to {output:?}");
138+
let mut file = tokio::fs::File::create(output).await?;
139+
file.write_all(config.as_bytes()).await?;
140+
} else {
141+
info!("Writing configuration to standard output");
142+
tokio::io::stdout().write_all(config.as_bytes()).await?;
143+
}
130144
}
131145

132146
SC::Check => {

0 commit comments

Comments
 (0)