~eanyanwu/jsn

0a55753a065174d91abe7312c80d1b7adb54e203 — Eze 2 months ago 035f543
Delete cli example

Masks are now statically dispatched. They can't be built dynamically
based on user input because the compiler needs to know the concrete
mask type at compile-time.
1 files changed, 0 insertions(+), 97 deletions(-)

D examples/cli.rs
D examples/cli.rs => examples/cli.rs +0 -97
@@ 1,97 0,0 @@
// use clap::Parser;
// use jsn::{mask::*, Format, TokenReader};
// use std::fs::File;
// use std::io::BufReader;

fn main() {
}
//
// /// Querying JSON using token masks
// ///
// /// This is a companion utility to the jsn (https://crates.io/crates/jsn) crate.
// #[derive(Parser)]
// #[command(version, author = "Eze Anyanwu")]
// struct Cli {
//     /// The JSON file to query
//     #[arg(short, long)]
//     file: String,
//
//     /// Combine masks using the bitwise `|` operator. Masks are combined using the bitwise
//     /// `&` operator by default
//     #[arg(long)]
//     or: bool,
//
//     /// Select tokens at the given depth.
//     #[arg(short, long)]
//     depth: Option<usize>,
//
//     /// Select the tokens at the given index. This can be sepecified multiple times
//     #[arg(short, long)]
//     index: Vec<usize>,
//
//     /// Select the tokens that are values of the given object key. This can be specified multiple
//     /// times
//     #[arg(short, long)]
//     key: Vec<String>,
//
//     /// Select tokens that are object keys
//     #[arg(long)]
//     keys: bool,
//
//     /// Select tokens that are values
//     #[arg(long)]
//     values: bool,
// }
//
// fn combine_masks(or: bool, a: impl Mask, b: impl Mask) -> impl Mask {
//     if or {
//         a.or(b)
//     } else {
//         a.and(b)
//     }
// }
//
// fn main() -> Result<(), Box<dyn std::error::Error>> {
//     let cli = Cli::parse();
//
//     let file = File::open(cli.file)?;
//     let buffered = BufReader::new(file);
//     let reader = TokenReader::new(buffered).with_format(Format::Regular);
//
//     let mut mask = all();
//
//     if let Some(d) = cli.depth {
//         mask = combine_masks(cli.or, mask, depth(d));
//     }
//
//     for i in cli.index {
//         mask = combine_masks(cli.or, mask, index(i));
//     }
//
//     for k in cli.key {
//         mask = combine_masks(cli.or, mask, key(k));
//     }
//
//     if cli.keys {
//         mask = combine_masks(cli.or, mask, keys());
//     }
//
//     if cli.values {
//         mask = combine_masks(cli.or, mask, values());
//     }
//
//     let mut iter = reader.with_mask(mask).into_iter();
//
//     // validate that the json is correct first
//     iter.dry_run()?;
//     iter.reset()?;
//
//     // print out the selected tokens
//     for token in iter.flatten() {
//         print!("{} ", token);
//     }
//
//     println!();
//
//     Ok(())
// }