From 8bc99917d2e8c2b558c243fc652b26b392e561da Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Wed, 17 Jan 2024 00:46:49 +0100 Subject: [PATCH] Simplify main --- src/cli.rs | 38 ------------------------------- src/main.rs | 65 ++++++++++++++++++++++++++++++++++------------------- 2 files changed, 42 insertions(+), 61 deletions(-) delete mode 100644 src/cli.rs diff --git a/src/cli.rs b/src/cli.rs deleted file mode 100644 index b755d41..0000000 --- a/src/cli.rs +++ /dev/null @@ -1,38 +0,0 @@ -#[derive(clap::Parser, Debug)] -#[command(author, version, about, long_about = None)] // Read from `Cargo.toml` -pub struct Parameters { - #[arg( - short = 'n', - long = "rust-fields-not-public", - env = "RUST_FIELDS_NOT_PUBLIC", - help = "Whether the fields in the generated rust code are marked 'pub'" - )] - pub rust_fields_not_public: bool, - #[arg( - short = 'g', - long = "rust-getter-and-setter", - env = "RUST_GETTER_AND_SETTER", - help = "Whether to generate getter and setter for the fields of the generated rust structs" - )] - pub rust_getter_and_setter: bool, - #[arg( - value_enum, - short = 't', - long = "convert-to", - env = "CONVERT_TO", - help = "The target to convert the input files to", - default_value = "rust" - )] - pub conversion_target: ConversionTarget, - #[arg(env = "DESTINATION_DIR")] - pub destination_dir: String, - #[arg(env = "SOURCE_FILES")] - pub source_files: Vec, -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)] -pub enum ConversionTarget { - Rust, - #[cfg(feature = "protobuf")] - Proto, -} diff --git a/src/main.rs b/src/main.rs index c8deac0..1c9e088 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,31 +1,11 @@ #![allow(dead_code)] #![warn(unused_extern_crates)] -#[cfg(feature = "macros")] -pub extern crate asn1rs_macros as macros; - -// provide an empty module, so that `use asn1rs::macros::*;` does not fail -#[cfg(not(feature = "macros"))] -pub mod macros {} - -#[macro_use] -pub mod internal_macros; - -#[macro_use] -extern crate serde_derive; - -pub mod io; -pub mod prelude; -pub mod syn; - -pub mod cli; -pub mod converter; - -use crate::cli::ConversionTarget; -use asn1rs::converter::Converter; +mod converter; +use converter::Converter; pub fn main() { - let params = ::parse(); + let params = ::parse(); let mut converter = Converter::default(); for source in ¶ms.source_files { @@ -56,3 +36,42 @@ pub fn main() { } } } + +#[derive(clap::Parser, Debug)] +#[command(author, version, about, long_about = None)] // Read from `Cargo.toml` +pub struct Parameters { + #[arg( + short = 'n', + long = "rust-fields-not-public", + env = "RUST_FIELDS_NOT_PUBLIC", + help = "Whether the fields in the generated rust code are marked 'pub'" + )] + pub rust_fields_not_public: bool, + #[arg( + short = 'g', + long = "rust-getter-and-setter", + env = "RUST_GETTER_AND_SETTER", + help = "Whether to generate getter and setter for the fields of the generated rust structs" + )] + pub rust_getter_and_setter: bool, + #[arg( + value_enum, + short = 't', + long = "convert-to", + env = "CONVERT_TO", + help = "The target to convert the input files to", + default_value = "rust" + )] + pub conversion_target: ConversionTarget, + #[arg(env = "DESTINATION_DIR")] + pub destination_dir: String, + #[arg(env = "SOURCE_FILES")] + pub source_files: Vec, +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)] +pub enum ConversionTarget { + Rust, + #[cfg(feature = "protobuf")] + Proto, +}