@@ -12,6 +12,16 @@ use std::{
12
12
path:: PathBuf ,
13
13
} ;
14
14
15
+ const BUG_REPORT_FLAG_ID : & str = "bugreport" ;
16
+ const LOG_FILE_FLAG_ID : & str = "logfile" ;
17
+ const LOGGING_FLAG_ID : & str = "logging" ;
18
+ const THEME_FLAG_ID : & str = "theme" ;
19
+ const WORKDIR_FLAG_ID : & str = "workdir" ;
20
+ const GIT_DIR_FLAG_ID : & str = "directory" ;
21
+ const WATCHER_FLAG_ID : & str = "watcher" ;
22
+ const DEFAULT_THEME : & str = "theme.ron" ;
23
+ const DEFAULT_GIT_DIR : & str = "." ;
24
+
15
25
pub struct CliArgs {
16
26
pub theme : PathBuf ,
17
27
pub repo_path : RepoPath ,
@@ -23,20 +33,23 @@ pub fn process_cmdline() -> Result<CliArgs> {
23
33
24
34
let arg_matches = app. get_matches ( ) ;
25
35
26
- if arg_matches. get_flag ( "bugreport" ) {
36
+ if arg_matches. get_flag ( BUG_REPORT_FLAG_ID ) {
27
37
bug_report:: generate_bugreport ( ) ;
28
38
std:: process:: exit ( 0 ) ;
29
39
}
30
- if arg_matches. get_flag ( "logging" ) {
31
- let logfile = arg_matches. get_one :: < String > ( "logfile" ) ;
40
+ if arg_matches. get_flag ( LOGGING_FLAG_ID ) {
41
+ let logfile = arg_matches. get_one :: < String > ( LOG_FILE_FLAG_ID ) ;
32
42
setup_logging ( logfile. map ( PathBuf :: from) ) ?;
33
43
}
34
44
35
- let workdir =
36
- arg_matches. get_one :: < String > ( "workdir" ) . map ( PathBuf :: from) ;
37
- let gitdir = arg_matches
38
- . get_one :: < String > ( "directory" )
39
- . map_or_else ( || PathBuf :: from ( "." ) , PathBuf :: from) ;
45
+ let workdir = arg_matches
46
+ . get_one :: < String > ( WORKDIR_FLAG_ID )
47
+ . map ( PathBuf :: from) ;
48
+ let gitdir =
49
+ arg_matches. get_one :: < String > ( GIT_DIR_FLAG_ID ) . map_or_else (
50
+ || PathBuf :: from ( DEFAULT_GIT_DIR ) ,
51
+ PathBuf :: from,
52
+ ) ;
40
53
41
54
let repo_path = if let Some ( w) = workdir {
42
55
RepoPath :: Workdir { gitdir, workdir : w }
@@ -45,8 +58,8 @@ pub fn process_cmdline() -> Result<CliArgs> {
45
58
} ;
46
59
47
60
let arg_theme = arg_matches
48
- . get_one :: < String > ( "theme" )
49
- . map_or_else ( || PathBuf :: from ( "theme.ron" ) , PathBuf :: from) ;
61
+ . get_one :: < String > ( THEME_FLAG_ID )
62
+ . map_or_else ( || PathBuf :: from ( DEFAULT_THEME ) , PathBuf :: from) ;
50
63
51
64
let confpath = get_app_config_path ( ) ?;
52
65
fs:: create_dir_all ( & confpath) . with_context ( || {
@@ -58,7 +71,7 @@ pub fn process_cmdline() -> Result<CliArgs> {
58
71
let theme = confpath. join ( arg_theme) ;
59
72
60
73
let notify_watcher: bool =
61
- * arg_matches. get_one ( "watcher" ) . unwrap_or ( & false ) ;
74
+ * arg_matches. get_one ( WATCHER_FLAG_ID ) . unwrap_or ( & false ) ;
62
75
63
76
Ok ( CliArgs {
64
77
theme,
@@ -84,48 +97,48 @@ fn app() -> ClapApp {
84
97
" ,
85
98
)
86
99
. arg (
87
- Arg :: new ( "theme" )
100
+ Arg :: new ( THEME_FLAG_ID )
88
101
. help ( "Set color theme filename loaded from config directory" )
89
102
. short ( 't' )
90
103
. long ( "theme" )
91
104
. value_name ( "THEME_FILE" )
92
- . default_value ( "theme.ron" )
105
+ . default_value ( DEFAULT_THEME )
93
106
. num_args ( 1 ) ,
94
107
)
95
108
. arg (
96
- Arg :: new ( "logging" )
109
+ Arg :: new ( LOGGING_FLAG_ID )
97
110
. help ( "Store logging output into a file (in the cache directory by default)" )
98
111
. short ( 'l' )
99
112
. long ( "logging" )
100
113
. default_value_if ( "logfile" , ArgPredicate :: IsPresent , "true" )
101
114
. action ( clap:: ArgAction :: SetTrue ) ,
102
115
)
103
- . arg ( Arg :: new ( "logfile" )
116
+ . arg ( Arg :: new ( LOG_FILE_FLAG_ID )
104
117
. help ( "Store logging output into the specified file (implies --logging)" )
105
118
. long ( "logfile" )
106
119
. value_name ( "LOG_FILE" ) )
107
120
. arg (
108
- Arg :: new ( "watcher" )
121
+ Arg :: new ( WATCHER_FLAG_ID )
109
122
. help ( "Use notify-based file system watcher instead of tick-based update. This is more performant, but can cause issues on some platforms. See https://github.com/gitui-org/gitui/blob/master/FAQ.md#watcher for details." )
110
123
. long ( "watcher" )
111
124
. action ( clap:: ArgAction :: SetTrue ) ,
112
125
)
113
126
. arg (
114
- Arg :: new ( "bugreport" )
127
+ Arg :: new ( BUG_REPORT_FLAG_ID )
115
128
. help ( "Generate a bug report" )
116
129
. long ( "bugreport" )
117
130
. action ( clap:: ArgAction :: SetTrue ) ,
118
131
)
119
132
. arg (
120
- Arg :: new ( "directory" )
133
+ Arg :: new ( GIT_DIR_FLAG_ID )
121
134
. help ( "Set the git directory" )
122
135
. short ( 'd' )
123
136
. long ( "directory" )
124
137
. env ( "GIT_DIR" )
125
138
. num_args ( 1 ) ,
126
139
)
127
140
. arg (
128
- Arg :: new ( "workdir" )
141
+ Arg :: new ( WORKDIR_FLAG_ID )
129
142
. help ( "Set the working directory" )
130
143
. short ( 'w' )
131
144
. long ( "workdir" )
0 commit comments