Skip to content

Commit

Permalink
Simplify main
Browse files Browse the repository at this point in the history
  • Loading branch information
kellerkindt committed Jan 16, 2024
1 parent 90d54fe commit 8bc9991
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 61 deletions.
38 changes: 0 additions & 38 deletions src/cli.rs

This file was deleted.

65 changes: 42 additions & 23 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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 = <cli::Parameters as clap::Parser>::parse();
let params = <Parameters as clap::Parser>::parse();
let mut converter = Converter::default();

for source in &params.source_files {
Expand Down Expand Up @@ -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<String>,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]
pub enum ConversionTarget {
Rust,
#[cfg(feature = "protobuf")]
Proto,
}

0 comments on commit 8bc9991

Please sign in to comment.