@@ -2,36 +2,27 @@ mod codegen;
2
2
mod cubemx;
3
3
4
4
use anyhow:: Result ;
5
- use clap:: { App , AppSettings , Arg , ArgMatches , SubCommand } ;
6
5
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
+ } ,
22
17
}
23
18
24
19
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) ,
30
22
}
31
23
}
32
24
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 < ( ) > {
35
26
let db = cubemx:: Db :: new ( db_path) ;
36
27
37
28
emit_autogen_comment ( & db) ?;
0 commit comments