Skip to content

Commit d861c05

Browse files
committed
fix(cli): use BufWriter for the output file
1 parent 2f78809 commit d861c05

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ thiserror = "1"
4646
tokio = { version = "1.23", features = ["macros", "rt-multi-thread"] }
4747
tokio-stream = "0.1"
4848
tracing = "0.1"
49+
tracing-subscriber = "0.3"
4950
url = "2"
5051

5152
[dev-dependencies]

cli/src/args.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use crate::{Format, Result, Subcommand};
22
use clap::Parser;
33
use stac::{Version, STAC_VERSION};
4-
use std::{fs::File, io::Write};
4+
use std::{
5+
fs::File,
6+
io::{BufWriter, Write},
7+
};
58

69
/// CLI arguments.
710
#[derive(Parser, Debug)]
@@ -243,7 +246,7 @@ impl Args {
243246
pub(crate) fn writer(&self) -> Result<Box<dyn Write + Send>> {
244247
if let Some(outfile) = self.subcommand.outfile() {
245248
let file = File::create(outfile)?;
246-
Ok(Box::new(file))
249+
Ok(Box::new(BufWriter::new(file)))
247250
} else {
248251
Ok(Box::new(std::io::stdout()))
249252
}

cli/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,6 @@ mod python {
137137
}
138138
}
139139

140+
use tracing_subscriber as _;
140141
#[cfg(test)]
141142
use {assert_cmd as _, tokio_test as _};

cli/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
use clap::Parser;
22
use stac_cli::Args;
3+
use tracing_subscriber;
34

45
#[tokio::main]
56
async fn main() {
7+
if std::env::var("STACRS_TRACING").is_ok() {
8+
tracing_subscriber::fmt::init();
9+
}
10+
611
let args = Args::parse();
712
std::process::exit(match stac_cli::run(args).await {
813
Ok(()) => 0,

cli/src/subcommand/translate.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use crate::{Format, Result, Subcommand, TranslateArgs};
22
use stac::Value;
3+
use tracing::{info, instrument};
34

45
impl Subcommand {
6+
#[instrument]
57
pub(crate) async fn translate(args: TranslateArgs, input_format: Format) -> Result<Value> {
8+
info!("reading {}", args.infile.as_deref().unwrap_or("<stdin>"));
69
input_format.read_href(args.infile.as_deref()).await
710
}
811
}

0 commit comments

Comments
 (0)