Skip to content

Commit f143f09

Browse files
shenekStephan Dilly
authored andcommitted
replaces GITUI_LOGGING env variable by -l or --gitui-logging cmdline arguments using clap
1 parent 32bd4e2 commit f143f09

File tree

3 files changed

+92
-10
lines changed

3 files changed

+92
-10
lines changed

Cargo.lock

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ keywords = [
2222
scopetime = { path = "./scopetime", version = "0.1" }
2323
asyncgit = { path = "./asyncgit", version = "0.4" }
2424
crossterm = "0.17"
25+
clap = "2.33"
2526
tui = { version = "0.9", default-features=false, features = ['crossterm'] }
2627
itertools = "0.9"
2728
rayon-core = "1.7"
@@ -50,4 +51,4 @@ members=[
5051
[profile.release]
5152
lto = true
5253
opt-level = 'z' # Optimize for size.
53-
codegen-units = 1
54+
codegen-units = 1

src/main.rs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ use crate::{app::App, poll::QueueEvent};
2323
use anyhow::{anyhow, Result};
2424
use asyncgit::AsyncNotification;
2525
use backtrace::Backtrace;
26+
use clap::{
27+
crate_authors, crate_description, crate_name, crate_version,
28+
App as ClapApp, Arg,
29+
};
2630
use crossbeam_channel::{tick, unbounded, Receiver, Select};
2731
use crossterm::{
2832
terminal::{
@@ -53,7 +57,7 @@ static TICK_INTERVAL: Duration = Duration::from_secs(5);
5357
static SPINNER_INTERVAL: Duration = Duration::from_millis(50);
5458

5559
fn main() -> Result<()> {
56-
setup_logging()?;
60+
process_cmdline()?;
5761

5862
if invalid_path() {
5963
eprintln!("invalid git path\nplease run gitui inside of a git repository");
@@ -205,15 +209,35 @@ fn get_app_config_path() -> Result<PathBuf> {
205209
}
206210

207211
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),
216236
);
237+
238+
let arg_matches = app.get_matches();
239+
if arg_matches.is_present("gitui-logging") {
240+
setup_logging()?;
217241
}
218242

219243
Ok(())

0 commit comments

Comments
 (0)