From a9ae5efffa01999e22e3349e7c31c289a6fa0f10 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Sun, 11 Sep 2022 22:35:30 +0200 Subject: [PATCH 1/2] Add command line parameter to specify log file I had the logs of my debug helix mixed in with the logs from the production helix. Add a `--log` command line argument to redirect any logs to other files, making my debugging easier :-) --- helix-term/src/args.rs | 5 +++++ helix-term/src/main.rs | 2 ++ 2 files changed, 7 insertions(+) diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs index d16d7dfdf3d4..48c866336fdb 100644 --- a/helix-term/src/args.rs +++ b/helix-term/src/args.rs @@ -14,6 +14,7 @@ pub struct Args { pub build_grammars: bool, pub split: Option, pub verbosity: u64, + pub log_file: Option, pub config_file: Option, pub files: Vec<(PathBuf, Position)>, } @@ -48,6 +49,10 @@ impl Args { Some(path) => args.config_file = Some(path.into()), None => anyhow::bail!("--config must specify a path to read"), }, + "--log" => match argv.next().as_deref() { + Some(path) => args.log_file = Some(path.into()), + None => anyhow::bail!("--log must specify a path to write"), + }, arg if arg.starts_with("--") => { anyhow::bail!("unexpected double dash argument: {}", arg) } diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index d21d3e778bf8..726bf9e3b667 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -67,6 +67,7 @@ FLAGS: -g, --grammar {{fetch|build}} Fetches or builds tree-sitter grammars listed in languages.toml -c, --config Specifies a file to use for configuration -v Increases logging verbosity each use for up to 3 times + --log Specifies a file to use for logging (default file: {}) -V, --version Prints version information --vsplit Splits all given files vertically into different windows @@ -114,6 +115,7 @@ FLAGS: return Ok(0); } + let logpath = args.log_file.as_ref().cloned().unwrap_or(logpath); setup_logging(logpath, args.verbosity).context("failed to initialize logging")?; let config_dir = helix_loader::config_dir(); From 7b85d6548a5be01a92d84b01ec84dad4ffbeeb93 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Tue, 13 Sep 2022 09:24:09 +0200 Subject: [PATCH 2/2] Update completion files with `--log` argument --- contrib/completion/hx.bash | 2 +- contrib/completion/hx.elv | 8 +++++++- contrib/completion/hx.fish | 1 + contrib/completion/hx.zsh | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/contrib/completion/hx.bash b/contrib/completion/hx.bash index 8a2d9777bc3f..89f3283c8257 100644 --- a/contrib/completion/hx.bash +++ b/contrib/completion/hx.bash @@ -16,7 +16,7 @@ _hx() { COMPREPLY=($(compgen -W "$languages" -- $2)) ;; *) - COMPREPLY=($(compgen -fd -W "-h --help --tutor -V --version -v -vv -vvv --health -g --grammar --vsplit --hsplit -c --config" -- $2)) + COMPREPLY=($(compgen -fd -W "-h --help --tutor -V --version -v -vv -vvv --health -g --grammar --vsplit --hsplit -c --config --log" -- $2)) ;; esac } && complete -F _hx hx diff --git a/contrib/completion/hx.elv b/contrib/completion/hx.elv index d3d227bcb566..42c88585c155 100644 --- a/contrib/completion/hx.elv +++ b/contrib/completion/hx.elv @@ -36,6 +36,11 @@ set edit:completion:arg-completer[hx] = {|@args| edit:complete-filename $args[-1] | each { |v| put $v[stem] } return } + # When we have --log, we need a file + if (has-values "log" $args[-2]) { + edit:complete-filename $args[-1] | each { |v| put $v[stem] } + return + } } edit:complete-filename $args[-1] | each { |v| put $v[stem]} $candidate "--help" "(Prints help information)" @@ -46,4 +51,5 @@ set edit:completion:arg-completer[hx] = {|@args| $candidate "--vsplit" "(Splits all given files vertically)" $candidate "--hsplit" "(Splits all given files horizontally)" $candidate "--config" "(Specifies a file to use for configuration)" -} \ No newline at end of file + $candidate "--log" "(Specifies a file to write log data into)" +} diff --git a/contrib/completion/hx.fish b/contrib/completion/hx.fish index 65f248d4234d..71c74ab04493 100644 --- a/contrib/completion/hx.fish +++ b/contrib/completion/hx.fish @@ -12,3 +12,4 @@ complete -c hx -s V -l version -d "Prints version information" complete -c hx -l vsplit -d "Splits all given files vertically into different windows" complete -c hx -l hsplit -d "Splits all given files horizontally into different windows" complete -c hx -s c -l config -d "Specifies a file to use for completion" +complete -c hx -s c -l log -d "Specifies a file to write log data into" diff --git a/contrib/completion/hx.zsh b/contrib/completion/hx.zsh index e3375656d65a..aaad6f844a08 100644 --- a/contrib/completion/hx.zsh +++ b/contrib/completion/hx.zsh @@ -18,6 +18,7 @@ _hx() { "--hsplit[Splits all given files horizontally into different windows]" \ "-c[Specifies a file to use for configuration]" \ "--config[Specifies a file to use for configuration]" \ + "--log[Specifies a file to write log data into]" \ "*:file:_files" case "$state" in