Various output formats
This commit is contained in:
parent
02420543f1
commit
a0bf6ebf41
|
@ -14,12 +14,14 @@ use preserves::value::NestedValue;
|
|||
use preserves::value::PackedReader;
|
||||
use preserves::value::PackedWriter;
|
||||
use preserves::value::Reader;
|
||||
use preserves::value::Set;
|
||||
use preserves::value::TextReader;
|
||||
use preserves::value::TextWriter;
|
||||
use preserves::value::Value;
|
||||
use preserves::value::ViaCodec;
|
||||
use preserves::value::Writer;
|
||||
|
||||
use std::iter::FromIterator;
|
||||
use std::io;
|
||||
use std::io::Read;
|
||||
|
||||
|
@ -66,6 +68,12 @@ impl From<Boolish> for bool {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(ArgEnum, Clone, Debug)]
|
||||
enum SelectOutput {
|
||||
Sequence,
|
||||
Set,
|
||||
}
|
||||
|
||||
#[derive(Clap, Clone, Debug)]
|
||||
struct Convert {
|
||||
// #[clap(long, arg_enum, default_value = "none")]
|
||||
|
@ -92,6 +100,12 @@ struct Convert {
|
|||
#[clap(long, default_value="*")]
|
||||
select: preserves_path::Node,
|
||||
|
||||
#[clap(long, arg_enum, default_value="sequence")]
|
||||
select_output: SelectOutput,
|
||||
|
||||
#[clap(long)]
|
||||
stream: bool,
|
||||
|
||||
#[clap(long, arg_enum, value_name = "on/off", default_value = "on")]
|
||||
annotations: Boolish,
|
||||
}
|
||||
|
@ -359,8 +373,17 @@ fn convert(c: Convert) -> io::Result<()> {
|
|||
};
|
||||
while let Some(value) = vs.next() {
|
||||
let value = value?;
|
||||
for v in c.select.exec(&value) {
|
||||
w(&v)?;
|
||||
let matches = c.select.exec(&value);
|
||||
if c.stream {
|
||||
match c.select_output {
|
||||
SelectOutput::Sequence => for v in matches { w(&v)?; },
|
||||
SelectOutput::Set => for v in Set::from_iter(matches) { w(&v)?; },
|
||||
}
|
||||
} else {
|
||||
match c.select_output {
|
||||
SelectOutput::Sequence => w(&IOValue::new(matches))?,
|
||||
SelectOutput::Set => w(&IOValue::new(Set::from_iter(matches)))?,
|
||||
}
|
||||
}
|
||||
if let Some(limit) = c.limit {
|
||||
if vs.count >= limit {
|
||||
|
|
Loading…
Reference in New Issue