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

Allow config dump to generate to a file directly instead of stdout #2146 #2234

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions crates/cli/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@
#[derive(Parser, Debug)]
enum Subcommand {
/// Dump the current config as YAML
Dump,
Dump {
/// The path to the config file to dump
///
/// If not specified, the config will be written to stdout
#[clap(short, long)]
output: Option<Utf8PathBuf>,
},

/// Check a config file
Check,
Expand Down Expand Up @@ -121,12 +127,20 @@
pub async fn run(self, root: &super::Options) -> anyhow::Result<()> {
use Subcommand as SC;
match self.subcommand {
SC::Dump => {
SC::Dump { output } => {

Check warning on line 130 in crates/cli/src/commands/config.rs

View check run for this annotation

Codecov / codecov/patch

crates/cli/src/commands/config.rs#L130

Added line #L130 was not covered by tests
let _span = info_span!("cli.config.dump").entered();

let config: RootConfig = root.load_config()?;
let config = serde_yaml::to_string(&config)?;

Check warning on line 134 in crates/cli/src/commands/config.rs

View check run for this annotation

Codecov / codecov/patch

crates/cli/src/commands/config.rs#L134

Added line #L134 was not covered by tests

serde_yaml::to_writer(std::io::stdout(), &config)?;
if let Some(output) = output {
info!("Writing configuration to {output:?}");
let mut file = tokio::fs::File::create(output).await?;
file.write_all(config.as_bytes()).await?;

Check warning on line 139 in crates/cli/src/commands/config.rs

View check run for this annotation

Codecov / codecov/patch

crates/cli/src/commands/config.rs#L136-L139

Added lines #L136 - L139 were not covered by tests
} else {
info!("Writing configuration to standard output");
tokio::io::stdout().write_all(config.as_bytes()).await?;

Check warning on line 142 in crates/cli/src/commands/config.rs

View check run for this annotation

Codecov / codecov/patch

crates/cli/src/commands/config.rs#L141-L142

Added lines #L141 - L142 were not covered by tests
}
}

SC::Check => {
Expand Down
Loading