Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45151b4a authored by Martin Geisler's avatar Martin Geisler Committed by Henri Chataing
Browse files

pdl: Update code for compatibility with Clap 2.3.3

tm-mainline-prod has 2.3.3 version, use 3.2.23 on aosp/master.
This is for integration with UWB.

Tag: #feature
Bug: 228306436
Test: atest pdl_tests pdl_rust_generator_tests_{le,be}
Change-Id: Ib242d348a845f05a56edf45101e1b5d6ed291893
parent 3bf1a9e0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ rust_defaults {
    name: "pdl_defaults",
    // LINT.IfChange
    rustlibs: [
        "libclap",
        "libclap_3.2.23",
        "libcodespan_reporting",
        "libheck",
        "libpest",
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ pest_derive = "2.4.0"
proc-macro2 = "1.0.46"
quote = "1.0.21"
serde_json = "1.0.86"
clap = { version = "3.2.22", features = ["derive"] }
clap = "3.2.23"
syn = "1.0.102"

[dependencies.serde]
+30 −17
Original line number Diff line number Diff line
//! PDL parser and analyzer.

use clap::Parser;
use codespan_reporting::term::{self, termcolor};

mod analyzer;
@@ -34,23 +33,48 @@ impl std::str::FromStr for OutputFormat {
    }
}

#[derive(Parser, Debug)]
#[clap(name = "pdl-parser", about = "Packet Description Language parser tool.")]
#[derive(Debug)]
struct Opt {
    /// Print tool version and exit.
    #[clap(short, long = "version")]
    version: bool,

    /// Generate output in this format ("json", "rust", "rust_no_alloc", "rust_no_alloc_test"). The output
    /// will be printed on stdout in both cases.
    #[clap(short, long = "output-format", name = "FORMAT", default_value = "JSON")]
    output_format: OutputFormat,

    /// Input file.
    #[clap(name = "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();

@@ -105,14 +129,3 @@ fn main() -> Result<(), String> {
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use clap::CommandFactory;

    #[test]
    fn verify_opt() {
        Opt::command().debug_assert();
    }
}