Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions rust/sbp2json/src/bin/json2json.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::fs::File;
use std::io;
use std::io::{Read, Write};
use std::path::PathBuf;

use clap::Parser;
use sbp::json::{CompactFormatter, HaskellishFloatFormatter};
Expand All @@ -12,10 +15,18 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
///
/// Typical usage:
///
/// json2json --input [PATH] --output [PATH]
Copy link
Contributor

@silverjam silverjam May 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update these example usage strings since we're not using option args (using positional args instead), example:

json2json [<INPUT> [<OUTPUT>]]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does --help show if we remove that completely? I feel like that's pretty similar to what clap will generate anyway

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, probably better to just remove this

///
/// cat console-json-log.json | json2json
#[derive(Debug, Parser)]
#[clap(name = "json2json", verbatim_doc_comment)]
struct Options {
/// Path to input file
input: Option<PathBuf>,

/// Path to output file
output: Option<PathBuf>,

/// Print debugging messages to standard error
#[clap(long)]
debug: bool,
Expand All @@ -42,8 +53,15 @@ fn main() -> Result<()> {

env_logger::init();

let stdin = io::stdin();
let stdout = io::stdout();
let stdin: Box<dyn Read> = match options.input {
Some(path) => Box::new(File::open(path)?),
_ => Box::new(io::stdin()),
};

let stdout: Box<dyn Write> = match options.output {
Some(path) => Box::new(File::create(path)?),
_ => Box::new(io::stdout()),
};

if options.float_compat {
json2json(
Expand Down
22 changes: 20 additions & 2 deletions rust/sbp2json/src/bin/json2sbp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::fs::File;
use std::io;
use std::io::{Read, Write};
use std::path::PathBuf;

use clap::Parser;

Expand All @@ -11,10 +14,18 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
///
/// Typical usage:
///
/// json2sbp --input [PATH] --output [PATH]
///
/// cat sbp.json | json2sbp
#[derive(Debug, Parser)]
#[clap(name = "json2sbp", verbatim_doc_comment)]
struct Options {
/// Path to input file
input: Option<PathBuf>,

/// Path to output file
output: Option<PathBuf>,

/// Print debugging messages to standard error
#[clap(long)]
debug: bool,
Expand All @@ -37,8 +48,15 @@ fn main() -> Result<()> {

env_logger::init();

let stdin = io::stdin();
let stdout = io::stdout();
let stdin: Box<dyn Read> = match options.input {
Some(path) => Box::new(File::open(path)?),
_ => Box::new(io::stdin()),
};

let stdout: Box<dyn Write> = match options.output {
Some(path) => Box::new(File::create(path)?),
_ => Box::new(io::stdout()),
};

json2sbp(stdin, stdout, options.buffered, options.fatal_errors)
}
22 changes: 20 additions & 2 deletions rust/sbp2json/src/bin/sbp2json.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::fs::File;
use std::io;
use std::io::{Read, Write};
use std::path::PathBuf;

use clap::Parser;
use sbp::json::{CompactFormatter, HaskellishFloatFormatter};
Expand All @@ -12,6 +15,8 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
///
/// Typical usage:
///
/// sbp2json --input [PATH] --output [PATH]
///
/// cat sbp.dat | sbp2json
///
/// Or combined with socat:
Expand All @@ -20,6 +25,12 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
#[derive(Debug, Parser)]
#[structopt(name = "sbp2json", verbatim_doc_comment)]
pub struct Options {
/// Path to input file
input: Option<PathBuf>,

/// Path to output file
output: Option<PathBuf>,

/// Try to be compatible with the float formatting of the Haskell version of sbp2json
#[clap(long)]
float_compat: bool,
Expand All @@ -46,8 +57,15 @@ fn main() -> Result<()> {

env_logger::init();

let stdin = io::stdin();
let stdout = io::stdout();
let stdin: Box<dyn Read> = match options.input {
Some(path) => Box::new(File::open(path)?),
_ => Box::new(io::stdin()),
};

let stdout: Box<dyn Write> = match options.output {
Some(path) => Box::new(File::create(path)?),
_ => Box::new(io::stdout()),
};

if options.float_compat {
sbp2json(
Expand Down