aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authora-kenji <aks.kenji@protonmail.com>2021-04-21 08:58:38 +0200
committera-kenji <aks.kenji@protonmail.com>2021-04-21 09:03:46 +0200
commit2c12e8ff8324b3ebaa10ac8162af09f5da295e1b (patch)
tree674d5988c5ca0a34e6931798467fed61b45da3cf
parentfix(release): beta tag breaks cargo install (diff)
downloadsl0ppij-2c12e8ff8324b3ebaa10ac8162af09f5da295e1b.tar.gz
sl0ppij-2c12e8ff8324b3ebaa10ac8162af09f5da295e1b.tar.xz
sl0ppij-2c12e8ff8324b3ebaa10ac8162af09f5da295e1b.zip
Change Config To Flag (#290)
This changes the `config` subcommand to a config flag. Add option subcommand for now, for the clearing of default path. Add `ZELLIJ_CONFIG` environment variable. The configuration locations are now as follows: * `--config` flag * `ZELLIJ_CONFIG` environment variable * default config location in that order.
-rw-r--r--assets/completions/_zellij53
-rw-r--r--assets/completions/zellij.bash42
-rw-r--r--assets/completions/zellij.fish9
-rw-r--r--src/cli.rs14
-rw-r--r--src/common/input/config.rs20
-rw-r--r--src/common/mod.rs2
6 files changed, 53 insertions, 87 deletions
diff --git a/assets/completions/_zellij b/assets/completions/_zellij
index 9eecf8e2..774a28fa 100644
--- a/assets/completions/_zellij
+++ b/assets/completions/_zellij
@@ -23,6 +23,8 @@ _zellij() {
'--data-dir=[Change where zellij looks for layouts and plugins]' \
'-l+[Path to a layout yaml file]' \
'--layout=[Path to a layout yaml file]' \
+'-c+[Change where zellij looks for the configuration]' \
+'--config=[Change where zellij looks for the configuration]' \
'-m[Send "move focused pane" to active zellij session]' \
'--move-focus[Send "move focused pane" to active zellij session]' \
'-d[]' \
@@ -40,34 +42,13 @@ _zellij() {
(( CURRENT += 1 ))
curcontext="${curcontext%:*:*}:zellij-command-$line[1]:"
case $line[1] in
- (c)
+ (option)
_arguments "${_arguments_options[@]}" \
'--clean[Disables loading of configuration file at default location]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
-'::path:_files' \
-&& ret=0
-;;
-(c)
-_arguments "${_arguments_options[@]}" \
-'--clean[Disables loading of configuration file at default location]' \
-'-h[Prints help information]' \
-'--help[Prints help information]' \
-'-V[Prints version information]' \
-'--version[Prints version information]' \
-'::path:_files' \
-&& ret=0
-;;
-(config)
-_arguments "${_arguments_options[@]}" \
-'--clean[Disables loading of configuration file at default location]' \
-'-h[Prints help information]' \
-'--help[Prints help information]' \
-'-V[Prints version information]' \
-'--version[Prints version information]' \
-'::path:_files' \
&& ret=0
;;
(help)
@@ -86,38 +67,24 @@ esac
(( $+functions[_zellij_commands] )) ||
_zellij_commands() {
local commands; commands=(
- "config:Path to the configuration yaml file" \
+ "option:Change the behaviour of zellij" \
"help:Prints this message or the help of the given subcommand(s)" \
)
_describe -t commands 'zellij commands' commands "$@"
}
-(( $+functions[_c_commands] )) ||
-_c_commands() {
- local commands; commands=(
-
- )
- _describe -t commands 'c commands' commands "$@"
-}
-(( $+functions[_zellij__c_commands] )) ||
-_zellij__c_commands() {
- local commands; commands=(
-
- )
- _describe -t commands 'zellij c commands' commands "$@"
-}
-(( $+functions[_zellij__config_commands] )) ||
-_zellij__config_commands() {
+(( $+functions[_zellij__help_commands] )) ||
+_zellij__help_commands() {
local commands; commands=(
)
- _describe -t commands 'zellij config commands' commands "$@"
+ _describe -t commands 'zellij help commands' commands "$@"
}
-(( $+functions[_zellij__help_commands] )) ||
-_zellij__help_commands() {
+(( $+functions[_zellij__option_commands] )) ||
+_zellij__option_commands() {
local commands; commands=(
)
- _describe -t commands 'zellij help commands' commands "$@"
+ _describe -t commands 'zellij option commands' commands "$@"
}
_zellij "$@" \ No newline at end of file
diff --git a/assets/completions/zellij.bash b/assets/completions/zellij.bash
index 4f28140a..9cd8f890 100644
--- a/assets/completions/zellij.bash
+++ b/assets/completions/zellij.bash
@@ -13,15 +13,12 @@ _zellij() {
cmd="zellij"
;;
- c)
- cmd+="__c"
- ;;
- config)
- cmd+="__config"
- ;;
help)
cmd+="__help"
;;
+ option)
+ cmd+="__option"
+ ;;
*)
;;
esac
@@ -29,7 +26,7 @@ _zellij() {
case "${cmd}" in
zellij)
- opts=" -m -d -h -V -s -o -l --move-focus --debug --help --version --split --open-file --max-panes --data-dir --layout config help c c"
+ opts=" -m -d -h -V -s -o -l -c --move-focus --debug --help --version --split --open-file --max-panes --data-dir --layout --config option help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
@@ -68,22 +65,14 @@ _zellij() {
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
- *)
- COMPREPLY=()
+ --config)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
+ -c)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
-
- zellij__c)
- opts=" -h -V --clean --help --version <path> "
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
-
*)
COMPREPLY=()
;;
@@ -91,8 +80,9 @@ _zellij() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
- zellij__config)
- opts=" -h -V --clean --help --version <path> "
+
+ zellij__help)
+ opts=" -h -V --help --version "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
@@ -106,8 +96,8 @@ _zellij() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
- zellij__help)
- opts=" -h -V --help --version "
+ zellij__option)
+ opts=" -h -V --clean --help --version "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
diff --git a/assets/completions/zellij.fish b/assets/completions/zellij.fish
index ec758be6..4c1e536f 100644
--- a/assets/completions/zellij.fish
+++ b/assets/completions/zellij.fish
@@ -3,14 +3,15 @@ complete -c zellij -n "__fish_use_subcommand" -s o -l open-file -d 'Send "open f
complete -c zellij -n "__fish_use_subcommand" -l max-panes -d 'Maximum panes on screen, caution: opening more panes will close old ones'
complete -c zellij -n "__fish_use_subcommand" -l data-dir -d 'Change where zellij looks for layouts and plugins'
complete -c zellij -n "__fish_use_subcommand" -s l -l layout -d 'Path to a layout yaml file'
+complete -c zellij -n "__fish_use_subcommand" -s c -l config -d 'Change where zellij looks for the configuration'
complete -c zellij -n "__fish_use_subcommand" -s m -l move-focus -d 'Send "move focused pane" to active zellij session'
complete -c zellij -n "__fish_use_subcommand" -s d -l debug
complete -c zellij -n "__fish_use_subcommand" -s h -l help -d 'Prints help information'
complete -c zellij -n "__fish_use_subcommand" -s V -l version -d 'Prints version information'
-complete -c zellij -n "__fish_use_subcommand" -f -a "config" -d 'Path to the configuration yaml file'
+complete -c zellij -n "__fish_use_subcommand" -f -a "option" -d 'Change the behaviour of zellij'
complete -c zellij -n "__fish_use_subcommand" -f -a "help" -d 'Prints this message or the help of the given subcommand(s)'
-complete -c zellij -n "__fish_seen_subcommand_from config" -l clean -d 'Disables loading of configuration file at default location'
-complete -c zellij -n "__fish_seen_subcommand_from config" -s h -l help -d 'Prints help information'
-complete -c zellij -n "__fish_seen_subcommand_from config" -s V -l version -d 'Prints version information'
+complete -c zellij -n "__fish_seen_subcommand_from option" -l clean -d 'Disables loading of configuration file at default location'
+complete -c zellij -n "__fish_seen_subcommand_from option" -s h -l help -d 'Prints help information'
+complete -c zellij -n "__fish_seen_subcommand_from option" -s V -l version -d 'Prints version information'
complete -c zellij -n "__fish_seen_subcommand_from help" -s h -l help -d 'Prints help information'
complete -c zellij -n "__fish_seen_subcommand_from help" -s V -l version -d 'Prints version information'
diff --git a/src/cli.rs b/src/cli.rs
index 43047dd3..008fb28c 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -1,6 +1,9 @@
use std::path::PathBuf;
use structopt::StructOpt;
+// TODO add to consts.rs
+const ZELLIJ_CONFIG_ENV: &str = "ZELLIJ_CONFIG";
+
#[derive(StructOpt, Default, Debug)]
#[structopt(name = "zellij")]
pub struct CliArgs {
@@ -28,8 +31,12 @@ pub struct CliArgs {
#[structopt(short, long)]
pub layout: Option<PathBuf>,
+ /// Change where zellij looks for the configuration
+ #[structopt(short, long, env=ZELLIJ_CONFIG_ENV)]
+ pub config: Option<PathBuf>,
+
#[structopt(subcommand)]
- pub config: Option<ConfigCli>,
+ pub option: Option<ConfigCli>,
#[structopt(short, long)]
pub debug: bool,
@@ -37,10 +44,9 @@ pub struct CliArgs {
#[derive(Debug, StructOpt)]
pub enum ConfigCli {
- /// Path to the configuration yaml file
- #[structopt(alias = "c")]
+ /// Change the behaviour of zellij
+ #[structopt(name = "option")]
Config {
- path: Option<PathBuf>,
#[structopt(long)]
/// Disables loading of configuration file at default location
clean: bool,
diff --git a/src/common/input/config.rs b/src/common/input/config.rs
index 1926b11c..17e1edf1 100644
--- a/src/common/input/config.rs
+++ b/src/common/input/config.rs
@@ -79,19 +79,23 @@ impl Config {
/// Entry point of the configuration
#[cfg(not(test))]
- pub fn from_cli_config(cli_config: Option<ConfigCli>) -> ConfigResult {
+ pub fn from_cli_config(
+ location: Option<PathBuf>,
+ cli_config: Option<ConfigCli>,
+ ) -> ConfigResult {
+ if let Some(path) = location {
+ return Config::new(&path);
+ }
+
match cli_config {
Some(ConfigCli::Config { clean, .. }) if clean => Ok(Config::default()),
- Some(ConfigCli::Config { path, .. }) if path.is_some() => {
- Ok(Config::new(&path.unwrap())?)
- }
Some(_) | None => Ok(Config::from_default_path()?),
}
}
/// In order not to mess up tests from changing configurations
#[cfg(test)]
- pub fn from_cli_config(_: Option<ConfigCli>) -> ConfigResult {
+ pub fn from_cli_config(_: Option<PathBuf>, _: Option<ConfigCli>) -> ConfigResult {
Ok(Config::default())
}
}
@@ -137,19 +141,17 @@ mod config_test {
#[test]
fn clean_option_equals_default_config() {
- let no_file = PathBuf::from(r"../fixtures/config/config.yamlll");
let cli_config = ConfigCli::Config {
- path: Some(no_file),
clean: true,
};
- let config = Config::from_cli_config(Some(cli_config)).unwrap();
+ let config = Config::from_cli_config(None, Some(cli_config)).unwrap();
let default = Config::default();
assert_eq!(config, default);
}
#[test]
fn no_config_option_file_equals_default_config() {
- let config = Config::from_cli_config(None).unwrap();
+ let config = Config::from_cli_config(None, None).unwrap();
let default = Config::default();
assert_eq!(config, default);
}
diff --git a/src/common/mod.rs b/src/common/mod.rs
index 860d12db..e2cd2220 100644
--- a/src/common/mod.rs
+++ b/src/common/mod.rs
@@ -128,7 +128,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
.write(take_snapshot.as_bytes())
.unwrap();
- let config = Config::from_cli_config(opts.config)
+ let config = Config::from_cli_config(opts.config, opts.option)
.map_err(|e| {
eprintln!("There was an error in the config file:\n{}", e);
std::process::exit(1);