Skip to content

Commit 9b89122

Browse files
committed
codegen: Replace clap with structopt
1 parent c9a0c7e commit 9b89122

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

codegen/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ once_cell = "1"
1010
regex = "1"
1111
serde-xml-rs = "0.4"
1212

13-
[dependencies.clap]
14-
version = "2"
13+
[dependencies.structopt]
14+
version = "0.3"
1515
default-features = false
1616

1717
[dependencies.serde]

codegen/src/main.rs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,27 @@ mod codegen;
22
mod cubemx;
33

44
use anyhow::Result;
5-
use clap::{App, AppSettings, Arg, ArgMatches, SubCommand};
65
use cubemx::Db;
7-
8-
fn parse_args() -> ArgMatches<'static> {
9-
App::new("codegen")
10-
.about("Code generation for the stm32f3xx-hal crate")
11-
.setting(AppSettings::SubcommandRequiredElseHelp)
12-
.subcommand(
13-
SubCommand::with_name("gpio")
14-
.about("Generate GPIO mappings from an STM32CubeMX database")
15-
.arg(
16-
Arg::with_name("db_path")
17-
.help("Path of the STM32CubeMX MCU database (.../db/mcs/)")
18-
.required(true),
19-
),
20-
)
21-
.get_matches()
6+
use std::path::PathBuf;
7+
use structopt::StructOpt;
8+
9+
#[derive(StructOpt)]
10+
#[structopt(about = "Code generation for the stm32f3xx-hal crate")]
11+
enum Command {
12+
#[structopt(about = "Generate GPIO mappings from an STM32CubeMX database")]
13+
Gpio {
14+
#[structopt(parse(from_os_str), help = "Path of the STM32CubeMX MCU database")]
15+
db_path: PathBuf,
16+
},
2217
}
2318

2419
fn main() -> Result<()> {
25-
let args = parse_args();
26-
27-
match args.subcommand() {
28-
("gpio", Some(args)) => handle_gpio(args),
29-
_ => unreachable!(),
20+
match Command::from_args() {
21+
Command::Gpio { db_path } => handle_gpio(db_path),
3022
}
3123
}
3224

33-
fn handle_gpio(args: &ArgMatches) -> Result<()> {
34-
let db_path = args.value_of("db_path").unwrap();
25+
fn handle_gpio(db_path: PathBuf) -> Result<()> {
3526
let db = cubemx::Db::new(db_path);
3627

3728
emit_autogen_comment(&db)?;

0 commit comments

Comments
 (0)