mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
replaces GITUI_LOGGING env variable by -l or --gitui-logging cmdline arguments using clap
This commit is contained in:
parent
32bd4e2c60
commit
f143f09ad8
3 changed files with 91 additions and 9 deletions
57
Cargo.lock
generated
57
Cargo.lock
generated
|
|
@ -9,6 +9,15 @@ dependencies = [
|
||||||
"gimli",
|
"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]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.31"
|
version = "1.0.31"
|
||||||
|
|
@ -46,6 +55,17 @@ dependencies = [
|
||||||
"thiserror",
|
"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]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
|
|
@ -126,6 +146,21 @@ dependencies = [
|
||||||
"time",
|
"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]]
|
[[package]]
|
||||||
name = "cloudabi"
|
name = "cloudabi"
|
||||||
version = "0.0.3"
|
version = "0.0.3"
|
||||||
|
|
@ -306,6 +341,7 @@ dependencies = [
|
||||||
"backtrace",
|
"backtrace",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"clap",
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"dirs",
|
"dirs",
|
||||||
|
|
@ -774,6 +810,12 @@ version = "1.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4"
|
checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.23"
|
version = "1.0.23"
|
||||||
|
|
@ -799,6 +841,15 @@ dependencies = [
|
||||||
"winapi 0.3.8",
|
"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]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "1.0.19"
|
version = "1.0.19"
|
||||||
|
|
@ -897,6 +948,12 @@ version = "0.2.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168"
|
checksum = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "vec_map"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasi"
|
name = "wasi"
|
||||||
version = "0.9.0+wasi-snapshot-preview1"
|
version = "0.9.0+wasi-snapshot-preview1"
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ keywords = [
|
||||||
scopetime = { path = "./scopetime", version = "0.1" }
|
scopetime = { path = "./scopetime", version = "0.1" }
|
||||||
asyncgit = { path = "./asyncgit", version = "0.4" }
|
asyncgit = { path = "./asyncgit", version = "0.4" }
|
||||||
crossterm = "0.17"
|
crossterm = "0.17"
|
||||||
|
clap = "2.33"
|
||||||
tui = { version = "0.9", default-features=false, features = ['crossterm'] }
|
tui = { version = "0.9", default-features=false, features = ['crossterm'] }
|
||||||
itertools = "0.9"
|
itertools = "0.9"
|
||||||
rayon-core = "1.7"
|
rayon-core = "1.7"
|
||||||
|
|
|
||||||
40
src/main.rs
40
src/main.rs
|
|
@ -23,6 +23,10 @@ use crate::{app::App, poll::QueueEvent};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use asyncgit::AsyncNotification;
|
use asyncgit::AsyncNotification;
|
||||||
use backtrace::Backtrace;
|
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 crossbeam_channel::{tick, unbounded, Receiver, Select};
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
terminal::{
|
terminal::{
|
||||||
|
|
@ -53,7 +57,7 @@ static TICK_INTERVAL: Duration = Duration::from_secs(5);
|
||||||
static SPINNER_INTERVAL: Duration = Duration::from_millis(50);
|
static SPINNER_INTERVAL: Duration = Duration::from_millis(50);
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
setup_logging()?;
|
process_cmdline()?;
|
||||||
|
|
||||||
if invalid_path() {
|
if invalid_path() {
|
||||||
eprintln!("invalid git path\nplease run gitui inside of a git repository");
|
eprintln!("invalid git path\nplease run gitui inside of a git repository");
|
||||||
|
|
@ -205,15 +209,35 @@ fn get_app_config_path() -> Result<PathBuf> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_logging() -> Result<()> {
|
fn setup_logging() -> Result<()> {
|
||||||
if env::var("GITUI_LOGGING").is_ok() {
|
let mut path = get_app_config_path()?;
|
||||||
let mut path = get_app_config_path()?;
|
path.push("gitui.log");
|
||||||
path.push("gitui.log");
|
|
||||||
|
|
||||||
let _ = WriteLogger::init(
|
let _ = WriteLogger::init(
|
||||||
LevelFilter::Trace,
|
LevelFilter::Trace,
|
||||||
Config::default(),
|
Config::default(),
|
||||||
File::create(path)?,
|
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(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue