diff --git a/Cargo.lock b/Cargo.lock index 8d22e90f..580fa1e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,6 +9,15 @@ dependencies = [ "gimli", ] +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi 0.3.8", +] + [[package]] name = "anyhow" version = "1.0.31" @@ -46,6 +55,17 @@ dependencies = [ "thiserror", ] +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi 0.3.8", +] + [[package]] name = "autocfg" version = "1.0.0" @@ -126,6 +146,21 @@ dependencies = [ "time", ] +[[package]] +name = "clap" +version = "2.33.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + [[package]] name = "cloudabi" version = "0.0.3" @@ -306,6 +341,7 @@ dependencies = [ "backtrace", "bitflags", "chrono", + "clap", "crossbeam-channel", "crossterm", "dirs", @@ -774,6 +810,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + [[package]] name = "syn" version = "1.0.23" @@ -799,6 +841,15 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + [[package]] name = "thiserror" version = "1.0.19" @@ -897,6 +948,12 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168" +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index 4863b830..b5dbe580 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ keywords = [ scopetime = { path = "./scopetime", version = "0.1" } asyncgit = { path = "./asyncgit", version = "0.4" } crossterm = "0.17" +clap = "2.33" tui = { version = "0.9", default-features=false, features = ['crossterm'] } itertools = "0.9" rayon-core = "1.7" @@ -50,4 +51,4 @@ members=[ [profile.release] lto = true opt-level = 'z' # Optimize for size. -codegen-units = 1 \ No newline at end of file +codegen-units = 1 diff --git a/src/main.rs b/src/main.rs index 08d4a463..f45aa387 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,6 +23,10 @@ use crate::{app::App, poll::QueueEvent}; use anyhow::{anyhow, Result}; use asyncgit::AsyncNotification; use backtrace::Backtrace; +use clap::{ + crate_authors, crate_description, crate_name, crate_version, + App as ClapApp, Arg, +}; use crossbeam_channel::{tick, unbounded, Receiver, Select}; use crossterm::{ terminal::{ @@ -53,7 +57,7 @@ static TICK_INTERVAL: Duration = Duration::from_secs(5); static SPINNER_INTERVAL: Duration = Duration::from_millis(50); fn main() -> Result<()> { - setup_logging()?; + process_cmdline()?; if invalid_path() { eprintln!("invalid git path\nplease run gitui inside of a git repository"); @@ -205,15 +209,35 @@ fn get_app_config_path() -> Result { } fn setup_logging() -> Result<()> { - if env::var("GITUI_LOGGING").is_ok() { - let mut path = get_app_config_path()?; - path.push("gitui.log"); + let mut path = get_app_config_path()?; + path.push("gitui.log"); - let _ = WriteLogger::init( - LevelFilter::Trace, - Config::default(), - File::create(path)?, + let _ = WriteLogger::init( + LevelFilter::Trace, + Config::default(), + File::create(path)?, + ); + + Ok(()) +} + +fn process_cmdline() -> Result<()> { + let app = ClapApp::new(crate_name!()) + .author(crate_authors!()) + .version(crate_version!()) + .about(crate_description!()) + .arg( + Arg::with_name("gitui-logging") + .help("Stores logging output into a cache directory") + .short("l") + .long("gitui-logging") + .takes_value(false) + .required(false), ); + + let arg_matches = app.get_matches(); + if arg_matches.is_present("gitui-logging") { + setup_logging()?; } Ok(())