@@ -2,36 +2,27 @@ mod codegen;
22mod cubemx;
33
44use anyhow:: Result ;
5- use clap:: { App , AppSettings , Arg , ArgMatches , SubCommand } ;
65use 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
2419fn 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