Support comma style option to preserves-tool
This commit is contained in:
parent
2e8d53c779
commit
7fdf50b963
|
@ -21,6 +21,8 @@ use preserves::value::Value;
|
||||||
use preserves::value::ViaCodec;
|
use preserves::value::ViaCodec;
|
||||||
use preserves::value::Writer;
|
use preserves::value::Writer;
|
||||||
|
|
||||||
|
use preserves::value::text::writer::CommaStyle;
|
||||||
|
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
@ -46,6 +48,13 @@ enum OutputFormat {
|
||||||
Unquoted,
|
Unquoted,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(ArgEnum, Clone, Debug)]
|
||||||
|
enum CommasFormat {
|
||||||
|
None,
|
||||||
|
Separating,
|
||||||
|
Terminating,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(ArgEnum, Clone, Debug)]
|
#[derive(ArgEnum, Clone, Debug)]
|
||||||
enum CompletionDialect {
|
enum CompletionDialect {
|
||||||
Bash,
|
Bash,
|
||||||
|
@ -69,6 +78,16 @@ impl From<Boolish> for bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<CommasFormat> for CommaStyle {
|
||||||
|
fn from(commas: CommasFormat) -> Self {
|
||||||
|
match commas {
|
||||||
|
CommasFormat::None => CommaStyle::None,
|
||||||
|
CommasFormat::Separating => CommaStyle::Separating,
|
||||||
|
CommasFormat::Terminating => CommaStyle::Terminating,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(ArgEnum, Clone, Debug)]
|
#[derive(ArgEnum, Clone, Debug)]
|
||||||
enum SelectOutput {
|
enum SelectOutput {
|
||||||
Sequence,
|
Sequence,
|
||||||
|
@ -92,6 +111,9 @@ struct Convert {
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
escape_spaces: bool,
|
escape_spaces: bool,
|
||||||
|
|
||||||
|
#[clap(long, short, arg_enum, default_value = "none")]
|
||||||
|
commas: CommasFormat,
|
||||||
|
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
limit: Option<usize>,
|
limit: Option<usize>,
|
||||||
|
|
||||||
|
@ -381,7 +403,9 @@ fn convert(c: Convert) -> io::Result<()> {
|
||||||
let write_ann: bool = c.write_annotations.into();
|
let write_ann: bool = c.write_annotations.into();
|
||||||
let mut w: Box<dyn FnMut(&IOValue) -> io::Result<()>> = match c.output_format {
|
let mut w: Box<dyn FnMut(&IOValue) -> io::Result<()>> = match c.output_format {
|
||||||
OutputFormat::Text => {
|
OutputFormat::Text => {
|
||||||
let mut t = TextWriter::new(io::stdout()).set_escape_spaces(c.escape_spaces);
|
let mut t = TextWriter::new(io::stdout())
|
||||||
|
.set_escape_spaces(c.escape_spaces)
|
||||||
|
.set_comma_style(c.commas.into());
|
||||||
if c.indent.into() {
|
if c.indent.into() {
|
||||||
t.indentation = 2;
|
t.indentation = 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ use std::io;
|
||||||
|
|
||||||
use super::super::boundary as B;
|
use super::super::boundary as B;
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum CommaStyle {
|
pub enum CommaStyle {
|
||||||
None,
|
None,
|
||||||
Separating,
|
Separating,
|
||||||
|
@ -59,6 +59,11 @@ impl<W: io::Write> TextWriter<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_comma_style(mut self, v: CommaStyle) -> Self {
|
||||||
|
self.comma_style = v;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_escape_spaces(mut self, v: bool) -> Self {
|
pub fn set_escape_spaces(mut self, v: bool) -> Self {
|
||||||
self.escape_spaces = v;
|
self.escape_spaces = v;
|
||||||
self
|
self
|
||||||
|
|
Loading…
Reference in New Issue