Skip to content

Commit 130793d

Browse files
authored
Add command line parameter to specify log file (#3807)
* 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 :-) * Update completion files with `--log` argument
1 parent 8988c1e commit 130793d

File tree

6 files changed

+17
-2
lines changed

6 files changed

+17
-2
lines changed

contrib/completion/hx.bash

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ _hx() {
1616
COMPREPLY=($(compgen -W "$languages" -- $2))
1717
;;
1818
*)
19-
COMPREPLY=($(compgen -fd -W "-h --help --tutor -V --version -v -vv -vvv --health -g --grammar --vsplit --hsplit -c --config" -- $2))
19+
COMPREPLY=($(compgen -fd -W "-h --help --tutor -V --version -v -vv -vvv --health -g --grammar --vsplit --hsplit -c --config --log" -- $2))
2020
;;
2121
esac
2222
} && complete -F _hx hx

contrib/completion/hx.elv

+7-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ set edit:completion:arg-completer[hx] = {|@args|
3636
edit:complete-filename $args[-1] | each { |v| put $v[stem] }
3737
return
3838
}
39+
# When we have --log, we need a file
40+
if (has-values "log" $args[-2]) {
41+
edit:complete-filename $args[-1] | each { |v| put $v[stem] }
42+
return
43+
}
3944
}
4045
edit:complete-filename $args[-1] | each { |v| put $v[stem]}
4146
$candidate "--help" "(Prints help information)"
@@ -46,4 +51,5 @@ set edit:completion:arg-completer[hx] = {|@args|
4651
$candidate "--vsplit" "(Splits all given files vertically)"
4752
$candidate "--hsplit" "(Splits all given files horizontally)"
4853
$candidate "--config" "(Specifies a file to use for configuration)"
49-
}
54+
$candidate "--log" "(Specifies a file to write log data into)"
55+
}

contrib/completion/hx.fish

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ complete -c hx -s V -l version -d "Prints version information"
1212
complete -c hx -l vsplit -d "Splits all given files vertically into different windows"
1313
complete -c hx -l hsplit -d "Splits all given files horizontally into different windows"
1414
complete -c hx -s c -l config -d "Specifies a file to use for completion"
15+
complete -c hx -s c -l log -d "Specifies a file to write log data into"

contrib/completion/hx.zsh

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ _hx() {
1818
"--hsplit[Splits all given files horizontally into different windows]" \
1919
"-c[Specifies a file to use for configuration]" \
2020
"--config[Specifies a file to use for configuration]" \
21+
"--log[Specifies a file to write log data into]" \
2122
"*:file:_files"
2223

2324
case "$state" in

helix-term/src/args.rs

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct Args {
1414
pub build_grammars: bool,
1515
pub split: Option<Layout>,
1616
pub verbosity: u64,
17+
pub log_file: Option<PathBuf>,
1718
pub config_file: Option<PathBuf>,
1819
pub files: Vec<(PathBuf, Position)>,
1920
}
@@ -48,6 +49,10 @@ impl Args {
4849
Some(path) => args.config_file = Some(path.into()),
4950
None => anyhow::bail!("--config must specify a path to read"),
5051
},
52+
"--log" => match argv.next().as_deref() {
53+
Some(path) => args.log_file = Some(path.into()),
54+
None => anyhow::bail!("--log must specify a path to write"),
55+
},
5156
arg if arg.starts_with("--") => {
5257
anyhow::bail!("unexpected double dash argument: {}", arg)
5358
}

helix-term/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ FLAGS:
6767
-g, --grammar {{fetch|build}} Fetches or builds tree-sitter grammars listed in languages.toml
6868
-c, --config <file> Specifies a file to use for configuration
6969
-v Increases logging verbosity each use for up to 3 times
70+
--log Specifies a file to use for logging
7071
(default file: {})
7172
-V, --version Prints version information
7273
--vsplit Splits all given files vertically into different windows
@@ -114,6 +115,7 @@ FLAGS:
114115
return Ok(0);
115116
}
116117

118+
let logpath = args.log_file.as_ref().cloned().unwrap_or(logpath);
117119
setup_logging(logpath, args.verbosity).context("failed to initialize logging")?;
118120

119121
let config_dir = helix_loader::config_dir();

0 commit comments

Comments
 (0)