Skip to content

Commit

Permalink
Add support for passing - for stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
Erin van der Veen committed Jan 30, 2024
1 parent 87d304b commit 5ea3e53
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::path::PathBuf;

use clap::Parser;
use nixtract::nixtract;

Expand Down Expand Up @@ -37,7 +35,7 @@ struct Args {
#[command(flatten)]
verbose: clap_verbosity_flag::Verbosity,
#[arg()]
output_path: Option<PathBuf>,
output_path: Option<String>,
}

fn main() {
Expand All @@ -64,10 +62,13 @@ fn main() {
serde_json::to_string(&results).unwrap()
};

if let Some(output_path) = opts.output_path {
log::info!("Writing results to {:?}", output_path);
std::fs::write(output_path, output).unwrap();
} else {
println!("{}", output);
match opts.output_path.as_deref() {
None | Some("-") => {
println!("{}", output);
}
Some(output_path) => {
log::info!("Writing results to {:?}", output_path);
std::fs::write(output_path, output).unwrap();
}
}
}

0 comments on commit 5ea3e53

Please sign in to comment.