@@ -23,6 +23,10 @@ use crate::{app::App, poll::QueueEvent};
23
23
use anyhow:: { anyhow, Result } ;
24
24
use asyncgit:: AsyncNotification ;
25
25
use backtrace:: Backtrace ;
26
+ use clap:: {
27
+ crate_authors, crate_description, crate_name, crate_version,
28
+ App as ClapApp , Arg ,
29
+ } ;
26
30
use crossbeam_channel:: { tick, unbounded, Receiver , Select } ;
27
31
use crossterm:: {
28
32
terminal:: {
@@ -53,7 +57,7 @@ static TICK_INTERVAL: Duration = Duration::from_secs(5);
53
57
static SPINNER_INTERVAL : Duration = Duration :: from_millis ( 50 ) ;
54
58
55
59
fn main ( ) -> Result < ( ) > {
56
- setup_logging ( ) ?;
60
+ process_cmdline ( ) ?;
57
61
58
62
if invalid_path ( ) {
59
63
eprintln ! ( "invalid git path\n please run gitui inside of a git repository" ) ;
@@ -205,15 +209,35 @@ fn get_app_config_path() -> Result<PathBuf> {
205
209
}
206
210
207
211
fn setup_logging ( ) -> Result < ( ) > {
208
- if env:: var ( "GITUI_LOGGING" ) . is_ok ( ) {
209
- let mut path = get_app_config_path ( ) ?;
210
- path. push ( "gitui.log" ) ;
211
-
212
- let _ = WriteLogger :: init (
213
- LevelFilter :: Trace ,
214
- Config :: default ( ) ,
215
- File :: create ( path) ?,
212
+ let mut path = get_app_config_path ( ) ?;
213
+ path. push ( "gitui.log" ) ;
214
+
215
+ let _ = WriteLogger :: init (
216
+ LevelFilter :: Trace ,
217
+ Config :: default ( ) ,
218
+ File :: create ( path) ?,
219
+ ) ;
220
+
221
+ Ok ( ( ) )
222
+ }
223
+
224
+ fn process_cmdline ( ) -> Result < ( ) > {
225
+ let app = ClapApp :: new ( crate_name ! ( ) )
226
+ . author ( crate_authors ! ( ) )
227
+ . version ( crate_version ! ( ) )
228
+ . about ( crate_description ! ( ) )
229
+ . arg (
230
+ Arg :: with_name ( "gitui-logging" )
231
+ . help ( "Stores logging output into a cache directory" )
232
+ . short ( "l" )
233
+ . long ( "gitui-logging" )
234
+ . takes_value ( false )
235
+ . required ( false ) ,
216
236
) ;
237
+
238
+ let arg_matches = app. get_matches ( ) ;
239
+ if arg_matches. is_present ( "gitui-logging" ) {
240
+ setup_logging ( ) ?;
217
241
}
218
242
219
243
Ok ( ( ) )
0 commit comments