Loading tools/pdl/Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ rust_defaults { name: "pdl_defaults", // LINT.IfChange rustlibs: [ "libclap_3.2.23", "libargh", "libcodespan_reporting", "libheck", "libpest", Loading tools/pdl/Cargo.toml +3 −3 Original line number Diff line number Diff line Loading @@ -12,12 +12,12 @@ default = ["serde"] [dependencies] codespan-reporting = "0.11.1" heck = "0.4.0" pest = "2.4.0" pest_derive = "2.4.0" pest = "2.5.5" pest_derive = "2.5.5" proc-macro2 = "1.0.46" quote = "1.0.21" serde_json = "1.0.86" clap = "3.2.23" argh = "0.1.7" syn = "1.0.102" [dependencies.serde] Loading tools/pdl/src/main.rs +10 −34 Original line number Diff line number Diff line //! PDL parser and analyzer. use argh::FromArgs; use codespan_reporting::term::{self, termcolor}; mod analyzer; Loading Loading @@ -33,50 +34,25 @@ impl std::str::FromStr for OutputFormat { } } #[derive(Debug)] #[derive(FromArgs, Debug)] /// PDL analyzer and generator. struct Opt { /// Print tool version and exit. #[argh(switch)] /// print tool version and exit. version: bool, /// Generate output in this format ("json", "rust", "rust_no_alloc", "rust_no_alloc_test"). The output #[argh(option, default = "OutputFormat::JSON")] /// generate output in this format ("json", "rust", "rust_no_alloc", "rust_no_alloc_test"). The output /// will be printed on stdout in both cases. output_format: OutputFormat, /// Input file. #[argh(positional)] /// input file. input_file: String, } impl Opt { fn parse() -> Opt { let app = clap::App::new("Packet Description Language parser") .version("1.0") .arg( clap::Arg::with_name("input-file") .value_name("FILE") .help("Input PDL file") .required(true), ) .arg( clap::Arg::with_name("output-format") .value_name("FORMAT") .long("output-format") .help("Output file format") .takes_value(true) .default_value("json") .possible_values(["json", "rust", "rust_no_alloc", "rust_no_alloc_test"]), ); let matches = app.get_matches(); Opt { version: matches.is_present("version"), input_file: matches.value_of("input-file").unwrap().into(), output_format: matches.value_of("output-format").unwrap().parse().unwrap(), } } } fn main() -> Result<(), String> { let opt = Opt::parse(); let opt: Opt = argh::from_env(); if opt.version { println!("Packet Description Language parser version 1.0"); Loading Loading
tools/pdl/Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ rust_defaults { name: "pdl_defaults", // LINT.IfChange rustlibs: [ "libclap_3.2.23", "libargh", "libcodespan_reporting", "libheck", "libpest", Loading
tools/pdl/Cargo.toml +3 −3 Original line number Diff line number Diff line Loading @@ -12,12 +12,12 @@ default = ["serde"] [dependencies] codespan-reporting = "0.11.1" heck = "0.4.0" pest = "2.4.0" pest_derive = "2.4.0" pest = "2.5.5" pest_derive = "2.5.5" proc-macro2 = "1.0.46" quote = "1.0.21" serde_json = "1.0.86" clap = "3.2.23" argh = "0.1.7" syn = "1.0.102" [dependencies.serde] Loading
tools/pdl/src/main.rs +10 −34 Original line number Diff line number Diff line //! PDL parser and analyzer. use argh::FromArgs; use codespan_reporting::term::{self, termcolor}; mod analyzer; Loading Loading @@ -33,50 +34,25 @@ impl std::str::FromStr for OutputFormat { } } #[derive(Debug)] #[derive(FromArgs, Debug)] /// PDL analyzer and generator. struct Opt { /// Print tool version and exit. #[argh(switch)] /// print tool version and exit. version: bool, /// Generate output in this format ("json", "rust", "rust_no_alloc", "rust_no_alloc_test"). The output #[argh(option, default = "OutputFormat::JSON")] /// generate output in this format ("json", "rust", "rust_no_alloc", "rust_no_alloc_test"). The output /// will be printed on stdout in both cases. output_format: OutputFormat, /// Input file. #[argh(positional)] /// input file. input_file: String, } impl Opt { fn parse() -> Opt { let app = clap::App::new("Packet Description Language parser") .version("1.0") .arg( clap::Arg::with_name("input-file") .value_name("FILE") .help("Input PDL file") .required(true), ) .arg( clap::Arg::with_name("output-format") .value_name("FORMAT") .long("output-format") .help("Output file format") .takes_value(true) .default_value("json") .possible_values(["json", "rust", "rust_no_alloc", "rust_no_alloc_test"]), ); let matches = app.get_matches(); Opt { version: matches.is_present("version"), input_file: matches.value_of("input-file").unwrap().into(), output_format: matches.value_of("output-format").unwrap().parse().unwrap(), } } } fn main() -> Result<(), String> { let opt = Opt::parse(); let opt: Opt = argh::from_env(); if opt.version { println!("Packet Description Language parser version 1.0"); Loading