@@ -6,14 +6,12 @@ mod emit;
66mod identifiers;
77mod parser_util;
88
9- fn main ( ) {
10- entry:: main ( ) ;
11- }
12-
139use std:: error:: Error ;
1410use std:: fs:: File ;
1511use std:: io:: { self , Read } ;
16- use std:: path:: Path ;
12+ use std:: path:: { Path , PathBuf } ;
13+
14+ use clap:: { Parser , Subcommand } ;
1715
1816use crate :: config:: Config ;
1917use crate :: parser_util:: JavaClass ;
@@ -97,49 +95,48 @@ fn gather_file(context: &mut emit::Context, path: &Path) -> Result<(), Box<dyn E
9795 Ok ( ( ) )
9896}
9997
100- mod entry {
101- use std:: path:: PathBuf ;
102-
103- use clap:: { Parser , Subcommand } ;
104-
105- use crate :: { config, run} ;
106-
107- /// Autogenerate glue code for access Android JVM APIs from Rust
108- #[ derive( Parser , Debug ) ]
109- #[ command( version, about) ]
110- struct Cli {
111- #[ command( subcommand) ]
112- cmd : Cmd ,
113- }
114-
115- /// Doc comment
116- #[ derive( Subcommand , Debug ) ]
117- enum Cmd {
118- Generate ( GenerateCmd ) ,
119- }
98+ /// Autogenerate glue code for access Android JVM APIs from Rust
99+ #[ derive( Parser , Debug ) ]
100+ #[ command( version, about) ]
101+ struct Cli {
102+ #[ command( subcommand) ]
103+ cmd : Cmd ,
104+ }
120105
121- # [ derive ( Parser , Debug ) ]
122- struct GenerateCmd {
123- /// Log in more detail
124- # [ arg ( short , long ) ]
125- verbose : bool ,
106+ /// Doc comment
107+ # [ derive ( Subcommand , Debug ) ]
108+ enum Cmd {
109+ Generate ( GenerateCmd ) ,
110+ }
126111
127- /// Sets a custom directory
128- #[ arg( short, long, default_value = "." ) ]
129- directory : PathBuf ,
130- }
112+ #[ derive( Parser , Debug ) ]
113+ struct GenerateCmd {
114+ /// Log in more detail
115+ #[ arg( short, long) ]
116+ verbose : bool ,
131117
132- pub fn main ( ) {
133- let cli = Cli :: parse ( ) ;
118+ /// Sets a custom config file
119+ #[ arg( short, long) ]
120+ config : Option < PathBuf > ,
121+ }
134122
135- match cli. cmd {
136- Cmd :: Generate ( cmd) => {
137- let mut config = config:: Config :: from_directory ( & cmd. directory ) . unwrap ( ) ;
138- if cmd. verbose {
139- config. logging_verbose = true ;
140- }
141- run ( config) . unwrap ( ) ;
123+ pub fn main ( ) {
124+ let cli = Cli :: parse ( ) ;
125+
126+ match cli. cmd {
127+ Cmd :: Generate ( cmd) => {
128+ let mut config = if let Some ( config_path) = cmd. config {
129+ // Use specified config file
130+ config:: Config :: from_file ( & config_path) . unwrap ( )
131+ } else {
132+ // Search from current working directory
133+ config:: Config :: from_current_directory ( ) . unwrap ( )
134+ } ;
135+
136+ if cmd. verbose {
137+ config. logging_verbose = true ;
142138 }
139+ run ( config) . unwrap ( ) ;
143140 }
144141 }
145142}
0 commit comments