From 018d606c7b544b81352042bcbba76f37ae956a12 Mon Sep 17 00:00:00 2001 From: Lena <126529524+acuteenvy@users.noreply.github.com> Date: Thu, 27 Feb 2025 00:18:05 +0100 Subject: [PATCH 1/3] Add `-f`, `--logfile` Add a command-line option to override the default log file path. --- src/args.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/args.rs b/src/args.rs index 74654220c1..73da94456e 100644 --- a/src/args.rs +++ b/src/args.rs @@ -2,8 +2,8 @@ use crate::bug_report; use anyhow::{anyhow, Result}; use asyncgit::sync::RepoPath; use clap::{ - crate_authors, crate_description, crate_name, Arg, - Command as ClapApp, + builder::ArgPredicate, crate_authors, crate_description, + crate_name, Arg, Command as ClapApp, }; use simplelog::{Config, LevelFilter, WriteLogger}; use std::{ @@ -28,7 +28,8 @@ pub fn process_cmdline() -> Result { std::process::exit(0); } if arg_matches.get_flag("logging") { - setup_logging()?; + let logfile = arg_matches.get_one::("logfile"); + setup_logging(logfile.map(PathBuf::from))?; } let workdir = @@ -87,11 +88,17 @@ fn app() -> ClapApp { ) .arg( Arg::new("logging") - .help("Stores logging output into a cache directory") + .help("Store logging output into a file (in the cache directory by default)") .short('l') .long("logging") - .num_args(0), + .default_value_if("logfile", ArgPredicate::IsPresent, "true") + .action(clap::ArgAction::SetTrue), ) + .arg(Arg::new("logfile") + .help("Store logging output into the specified file (implies --logging)") + .short('f') + .long("logfile") + .value_name("LOG_FILE")) .arg( Arg::new("watcher") .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/extrawurst/gitui/blob/master/FAQ.md#watcher for details.") @@ -122,11 +129,16 @@ fn app() -> ClapApp { ) } -fn setup_logging() -> Result<()> { - let mut path = get_app_cache_path()?; - path.push("gitui.log"); +fn setup_logging(path_override: Option) -> Result<()> { + let path = if let Some(path) = path_override { + path + } else { + let mut path = get_app_cache_path()?; + path.push("gitui.log"); + path + }; - println!("Logging enabled. log written to: {path:?}"); + println!("Logging enabled. Log written to: {path:?}"); WriteLogger::init( LevelFilter::Trace, From 4a328c641a2a5769970d027308da906a689d16be Mon Sep 17 00:00:00 2001 From: Lena <126529524+acuteenvy@users.noreply.github.com> Date: Thu, 27 Feb 2025 00:28:40 +0100 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c47274c74..cefcc003ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added +* new command-line options: `-f` and `--logfile` to override the default log file path [[@acuteenvy](https://github.com/acuteenvy)] ([#2539](https://github.com/gitui-org/gitui/pull/2539)) + ### Changed * improve syntax highlighting file detection [[@acuteenvy](https://github.com/acuteenvy)] ([#2524](https://github.com/extrawurst/gitui/pull/2524)) * After commit: jump back to unstaged area [[@tommady](https://github.com/tommady)] ([#2476](https://github.com/extrawurst/gitui/issues/2476)) From 27cd77ea83a9b99bfcd181bd43f1789d3710a7a9 Mon Sep 17 00:00:00 2001 From: Lena <126529524+acuteenvy@users.noreply.github.com> Date: Wed, 12 Mar 2025 17:39:10 +0100 Subject: [PATCH 3/3] Remove the short option `-f` --- CHANGELOG.md | 2 +- src/args.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cefcc003ca..d8745f2c3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased ### Added -* new command-line options: `-f` and `--logfile` to override the default log file path [[@acuteenvy](https://github.com/acuteenvy)] ([#2539](https://github.com/gitui-org/gitui/pull/2539)) +* new command-line option to override the default log file path (`--logfile`) [[@acuteenvy](https://github.com/acuteenvy)] ([#2539](https://github.com/gitui-org/gitui/pull/2539)) ### Changed * improve syntax highlighting file detection [[@acuteenvy](https://github.com/acuteenvy)] ([#2524](https://github.com/extrawurst/gitui/pull/2524)) diff --git a/src/args.rs b/src/args.rs index 73da94456e..129f208eee 100644 --- a/src/args.rs +++ b/src/args.rs @@ -96,7 +96,6 @@ fn app() -> ClapApp { ) .arg(Arg::new("logfile") .help("Store logging output into the specified file (implies --logging)") - .short('f') .long("logfile") .value_name("LOG_FILE")) .arg(