File tree 2 files changed +11
-20
lines changed
2 files changed +11
-20
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ pub struct Args {
36
36
short,
37
37
long,
38
38
value_parser = parse_absolute_path,
39
+ default_value_os_t = find_weidu_bin( ) ,
39
40
default_missing_value = find_weidu_bin_on_path( ) ,
40
41
required = weidu_bin_not_on_path( )
41
42
) ]
@@ -142,28 +143,24 @@ fn parse_absolute_path(arg: &str) -> Result<PathBuf, String> {
142
143
}
143
144
}
144
145
145
- fn weidu_bin_not_on_path ( ) -> bool {
146
+ fn find_weidu_bin ( ) -> PathBuf {
146
147
if let Some ( paths) = var_os ( "PATH" ) {
147
148
for path in split_paths ( & paths) {
148
149
let full_path = path. join ( WEIDU_FILE_NAME ) ;
149
- if full_path. is_file ( ) {
150
- return false ;
150
+ if full_path. is_file ( ) && !full_path . is_dir ( ) {
151
+ return full_path
151
152
}
152
153
}
153
154
}
154
- true
155
+ PathBuf :: new ( )
155
156
}
156
157
157
158
fn find_weidu_bin_on_path ( ) -> OsStr {
158
- if let Some ( paths) = var_os ( "PATH" ) {
159
- for path in split_paths ( & paths) {
160
- let full_path = path. join ( WEIDU_FILE_NAME ) ;
161
- if full_path. is_file ( ) {
162
- return OsStr :: from ( full_path. into_os_string ( ) ) ;
163
- }
164
- }
165
- }
166
- OsStr :: from ( "" )
159
+ OsStr :: from ( find_weidu_bin ( ) . into_os_string ( ) )
160
+ }
161
+
162
+ fn weidu_bin_not_on_path ( ) -> bool {
163
+ find_weidu_bin ( ) . is_file ( )
167
164
}
168
165
169
166
#[ cfg( test) ]
Original file line number Diff line number Diff line change @@ -31,13 +31,7 @@ fn main() -> ExitCode {
31
31
\/ \/\___/ \__,_| |_|_| |_|___/\__\__,_|_|_|\___|_|
32
32
"
33
33
) ;
34
- let args = match Args :: try_parse ( ) {
35
- Ok ( args) => args,
36
- Err ( err) => {
37
- log:: error!( "Could not parse args, {}" , err) ;
38
- return ExitCode :: FAILURE ;
39
- }
40
- } ;
34
+ let args = Args :: parse ( ) ;
41
35
let parser_config: Arc < ParserConfig > = match confy:: load ( CARGO_PKG_NAME , "config" ) {
42
36
Ok ( config) => Arc :: new ( config) ,
43
37
Err ( err) => {
You can’t perform that action at this time.
0 commit comments