Skip to content

Commit

Permalink
datashed: add --stdout option (index) (#37)
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Wagner <[email protected]>
  • Loading branch information
nwagner84 authored Jul 15, 2024
1 parent c5778ad commit 10431a4
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions crates/datashed/src/commands/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ pub(crate) struct Index {
#[arg(short, long, conflicts_with = "verbose")]
quiet: bool,

/// Write the index into `filename`. By default, the index will
/// be written to stdout in CSV format.
/// If set, the index will be written in CSV format to the standard
/// output (stdout).
#[arg(long, conflicts_with = "output")]
stdout: bool,

/// Write the index into `filename`. By default (if `--stdout`
/// isn't set), the index will be written to `index.ipc` into
/// the root directory.
#[arg(short, long, value_name = "filename")]
output: Option<PathBuf>,
}
Expand Down Expand Up @@ -111,15 +117,22 @@ impl Index {
])?;

match self.output {
None => {
let mut writer = CsvWriter::new(stdout().lock());
writer.finish(&mut df)?;
}
Some(path) => {
let mut writer = IpcWriter::new(File::create(path)?)
.with_compression(Some(IpcCompression::ZSTD));
writer.finish(&mut df)?;
}
None if self.stdout => {
let mut writer = CsvWriter::new(stdout().lock());
writer.finish(&mut df)?;
}
None => {
let mut writer = IpcWriter::new(File::create(
base_dir.join(Datashed::INDEX),
)?)
.with_compression(Some(IpcCompression::ZSTD));
writer.finish(&mut df)?;
}
}

Ok(())
Expand Down

0 comments on commit 10431a4

Please sign in to comment.