@@ -18,6 +18,46 @@ pub struct CliArgs {
18
18
}
19
19
20
20
pub fn process_cmdline ( ) -> Result < CliArgs > {
21
+ let app = app ( ) ;
22
+
23
+ let arg_matches = app. get_matches ( ) ;
24
+ if arg_matches. is_present ( "bugreport" ) {
25
+ bug_report:: generate_bugreport ( ) ;
26
+ std:: process:: exit ( 0 ) ;
27
+ }
28
+ if arg_matches. is_present ( "logging" ) {
29
+ setup_logging ( ) ?;
30
+ }
31
+
32
+ let workdir = arg_matches. value_of ( "workdir" ) . map ( PathBuf :: from) ;
33
+ let gitdir = arg_matches
34
+ . value_of ( "directory" )
35
+ . map_or_else ( || PathBuf :: from ( "." ) , PathBuf :: from) ;
36
+
37
+ #[ allow( clippy:: option_if_let_else) ]
38
+ let repo_path = if let Some ( w) = workdir {
39
+ RepoPath :: Workdir { gitdir, workdir : w }
40
+ } else {
41
+ RepoPath :: Path ( gitdir)
42
+ } ;
43
+
44
+ let arg_theme =
45
+ arg_matches. value_of ( "theme" ) . unwrap_or ( "theme.ron" ) ;
46
+
47
+ if get_app_config_path ( ) ?. join ( arg_theme) . is_file ( ) {
48
+ Ok ( CliArgs {
49
+ theme : get_app_config_path ( ) ?. join ( arg_theme) ,
50
+ repo_path,
51
+ } )
52
+ } else {
53
+ Ok ( CliArgs {
54
+ theme : get_app_config_path ( ) ?. join ( "theme.ron" ) ,
55
+ repo_path,
56
+ } )
57
+ }
58
+ }
59
+
60
+ fn app ( ) -> ClapApp < ' static > {
21
61
let app = ClapApp :: new ( crate_name ! ( ) )
22
62
. author ( crate_authors ! ( ) )
23
63
. version ( crate_version ! ( ) )
@@ -57,42 +97,7 @@ pub fn process_cmdline() -> Result<CliArgs> {
57
97
. env ( "GIT_WORK_TREE" )
58
98
. takes_value ( true ) ,
59
99
) ;
60
-
61
- let arg_matches = app. get_matches ( ) ;
62
- if arg_matches. is_present ( "bugreport" ) {
63
- bug_report:: generate_bugreport ( ) ;
64
- std:: process:: exit ( 0 ) ;
65
- }
66
- if arg_matches. is_present ( "logging" ) {
67
- setup_logging ( ) ?;
68
- }
69
-
70
- let workdir = arg_matches. value_of ( "workdir" ) . map ( PathBuf :: from) ;
71
- let gitdir = arg_matches
72
- . value_of ( "directory" )
73
- . map_or_else ( || PathBuf :: from ( "." ) , PathBuf :: from) ;
74
-
75
- #[ allow( clippy:: option_if_let_else) ]
76
- let repo_path = if let Some ( w) = workdir {
77
- RepoPath :: Workdir { gitdir, workdir : w }
78
- } else {
79
- RepoPath :: Path ( gitdir)
80
- } ;
81
-
82
- let arg_theme =
83
- arg_matches. value_of ( "theme" ) . unwrap_or ( "theme.ron" ) ;
84
-
85
- if get_app_config_path ( ) ?. join ( arg_theme) . is_file ( ) {
86
- Ok ( CliArgs {
87
- theme : get_app_config_path ( ) ?. join ( arg_theme) ,
88
- repo_path,
89
- } )
90
- } else {
91
- Ok ( CliArgs {
92
- theme : get_app_config_path ( ) ?. join ( "theme.ron" ) ,
93
- repo_path,
94
- } )
95
- }
100
+ app
96
101
}
97
102
98
103
fn setup_logging ( ) -> Result < ( ) > {
@@ -129,3 +134,8 @@ pub fn get_app_config_path() -> Result<PathBuf> {
129
134
fs:: create_dir_all ( & path) ?;
130
135
Ok ( path)
131
136
}
137
+
138
+ #[ test]
139
+ fn verify_app ( ) {
140
+ app ( ) . debug_assert ( ) ;
141
+ }
0 commit comments