Skip to content

Commit

Permalink
completions: complete setting names (#1166)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored Dec 13, 2023
1 parent 631c53d commit fff00ef
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 34 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ v20.0.0
- [`rtx prune [OPTIONS] [PLUGIN]...`](#rtx-prune-options-plugin)
- [`rtx reshim`](#rtx-reshim)
- [`rtx self-update [OPTIONS] [VERSION]`](#rtx-self-update-options-version)
- [`rtx settings get <KEY>`](#rtx-settings-get-key)
- [`rtx settings get <SETTING>`](#rtx-settings-get-setting)
- [`rtx settings ls`](#rtx-settings-ls)
- [`rtx settings set <KEY> <VALUE>`](#rtx-settings-set-key-value)
- [`rtx settings unset <KEY>`](#rtx-settings-unset-key)
- [`rtx settings set <SETTING> <VALUE>`](#rtx-settings-set-setting-value)
- [`rtx settings unset <SETTING>`](#rtx-settings-unset-setting)
- [`rtx shell [OPTIONS] [TOOL@VERSION]...`](#rtx-shell-options-toolversion)
- [`rtx sync node <--brew|--nvm|--nodenv>`](#rtx-sync-node---brew--nvm--nodenv)
- [`rtx sync python --pyenv`](#rtx-sync-python---pyenv)
Expand Down Expand Up @@ -2456,7 +2456,7 @@ Options:
Skip confirmation prompt
```

### `rtx settings get <KEY>`
### `rtx settings get <SETTING>`

```text
Show a current setting
Expand All @@ -2466,10 +2466,10 @@ This is the contents of a single entry in ~/.config/rtx/config.toml
Note that aliases are also stored in this file
but managed separately with `rtx aliases get`
Usage: settings get <KEY>
Usage: settings get <SETTING>
Arguments:
<KEY>
<SETTING>
The setting to show
Examples:
Expand All @@ -2494,17 +2494,17 @@ Examples:
legacy_version_file = false
```

### `rtx settings set <KEY> <VALUE>`
### `rtx settings set <SETTING> <VALUE>`

```text
Add/update a setting
This modifies the contents of ~/.config/rtx/config.toml
Usage: settings set <KEY> <VALUE>
Usage: settings set <SETTING> <VALUE>
Arguments:
<KEY>
<SETTING>
The setting to set
<VALUE>
Expand All @@ -2514,17 +2514,17 @@ Examples:
$ rtx settings set legacy_version_file true
```

### `rtx settings unset <KEY>`
### `rtx settings unset <SETTING>`

```text
Clears a setting
This modifies the contents of ~/.config/rtx/config.toml
Usage: settings unset <KEY>
Usage: settings unset <SETTING>
Arguments:
<KEY>
<SETTING>
The setting to remove
Examples:
Expand Down
11 changes: 8 additions & 3 deletions completions/_rtx
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ return ret
(( $+functions[__rtx_settings_get_cmd] )) ||
__rtx_settings_get_cmd() {
_arguments -s -S \
':key:' \
':setting:__rtx_settings' \
'(-j --jobs)'{-j,--jobs}'=[Number of plugins and runtimes to install in parallel]:jobs:' \
'(-q --quiet)'{-q,--quiet}'[Suppress output]' \
'(-r --raw)'{-r,--raw}'[Directly pipe stdin/stdout/stderr to user.]' \
Expand All @@ -621,7 +621,7 @@ __rtx_settings_ls_cmd() {
(( $+functions[__rtx_settings_set_cmd] )) ||
__rtx_settings_set_cmd() {
_arguments -s -S \
':key:' \
':setting:__rtx_settings' \
':value:' \
'(-j --jobs)'{-j,--jobs}'=[Number of plugins and runtimes to install in parallel]:jobs:' \
'(-q --quiet)'{-q,--quiet}'[Suppress output]' \
Expand All @@ -632,7 +632,7 @@ __rtx_settings_set_cmd() {
(( $+functions[__rtx_settings_unset_cmd] )) ||
__rtx_settings_unset_cmd() {
_arguments -s -S \
':key:' \
':setting:__rtx_settings' \
'(-j --jobs)'{-j,--jobs}'=[Number of plugins and runtimes to install in parallel]:jobs:' \
'(-q --quiet)'{-q,--quiet}'[Suppress output]' \
'(-r --raw)'{-r,--raw}'[Directly pipe stdin/stdout/stderr to user.]' \
Expand Down Expand Up @@ -911,6 +911,11 @@ __rtx_aliases() {
local -a aliases; aliases=($(rtx aliases ls ${words[CURRENT-1]} | awk '{print $2}'))
_describe -t aliases 'alias' aliases "$@"
}
(( $+functions[__rtx_settings] )) ||
__rtx_settings() {
local -a settings; settings=($(rtx settings ls | awk '{print $1}'))
_describe -t settings 'setting' settings "$@"
}
(( $+functions[__rtx_prefixes] )) ||
__rtx_prefixes() {
if [[ CURRENT -gt 2 ]]; then
Expand Down
6 changes: 3 additions & 3 deletions completions/rtx.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3023,7 +3023,7 @@ _rtx() {
return 0
;;
rtx__settings__get)
opts="-j -q -r -v -y -h --jobs --debug --log-level --trace --quiet --raw --verbose --yes --help <KEY>"
opts="-j -q -r -v -y -h --jobs --debug --log-level --trace --quiet --raw --verbose --yes --help <SETTING>"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -3159,7 +3159,7 @@ _rtx() {
return 0
;;
rtx__settings__set)
opts="-j -q -r -v -y -h --jobs --debug --log-level --trace --quiet --raw --verbose --yes --help <KEY> <VALUE>"
opts="-j -q -r -v -y -h --jobs --debug --log-level --trace --quiet --raw --verbose --yes --help <SETTING> <VALUE>"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand All @@ -3185,7 +3185,7 @@ _rtx() {
return 0
;;
rtx__settings__unset)
opts="-j -q -r -v -y -h --jobs --debug --log-level --trace --quiet --raw --verbose --yes --help <KEY>"
opts="-j -q -r -v -y -h --jobs --debug --log-level --trace --quiet --raw --verbose --yes --help <SETTING>"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down
28 changes: 22 additions & 6 deletions completions/rtx.fish
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ complete -xc rtx -n "$fssf alias; and not $fssf $others" -a set -d 'Add/update a
complete -xc rtx -n "$fssf alias; and not $fssf $others" -a unset -d 'Clears an alias for a plugin'

# alias get
complete -kxc rtx -n "$fssf alias; and $fssf get" -d 'The alias to show'
complete -kxc rtx -n "$fssf alias; and $fssf get" -a "(__rtx_aliases)" -d 'The alias to show'
complete -kxc rtx -n "$fssf alias; and $fssf get" -a "(__rtx_plugins)" -d 'The plugin to show the alias for'

# alias ls
complete -kxc rtx -n "$fssf alias; and $fssf ls" -a "(__rtx_plugins)" -d 'Show aliases for <PLUGIN>'

# alias set
complete -kxc rtx -n "$fssf alias; and $fssf set" -d 'The alias to set'
complete -kxc rtx -n "$fssf alias; and $fssf set" -a "(__rtx_aliases)" -d 'The alias to set'
complete -kxc rtx -n "$fssf alias; and $fssf set" -a "(__rtx_plugins)" -d 'The plugin to set the alias for'
complete -kxc rtx -n "$fssf alias; and $fssf set" -d 'The value to set the alias to'

# alias unset
complete -kxc rtx -n "$fssf alias; and $fssf unset" -d 'The alias to remove'
complete -kxc rtx -n "$fssf alias; and $fssf unset" -a "(__rtx_aliases)" -d 'The alias to remove'
complete -kxc rtx -n "$fssf alias; and $fssf unset" -a "(__rtx_plugins)" -d 'The plugin to remove the alias from'


Expand Down Expand Up @@ -212,16 +212,16 @@ complete -xc rtx -n "$fssf settings; and not $fssf $others" -a set -d 'Add/updat
complete -xc rtx -n "$fssf settings; and not $fssf $others" -a unset -d 'Clears a setting'
# settings get
complete -kxc rtx -n "$fssf settings; and $fssf get" -d 'The setting to show'
complete -kxc rtx -n "$fssf settings; and $fssf get" -a "(__rtx_settings)" -d 'The setting to show'
# settings ls
# settings set
complete -kxc rtx -n "$fssf settings; and $fssf set" -d 'The setting to set'
complete -kxc rtx -n "$fssf settings; and $fssf set" -a "(__rtx_settings)" -d 'The setting to set'
complete -kxc rtx -n "$fssf settings; and $fssf set" -d 'The value to set'
# settings unset
complete -kxc rtx -n "$fssf settings; and $fssf unset" -d 'The setting to remove'
complete -kxc rtx -n "$fssf settings; and $fssf unset" -a "(__rtx_settings)" -d 'The setting to remove'
# shell
Expand Down Expand Up @@ -309,5 +309,21 @@ function __rtx_installed_tool_versions
echo $tv
end
end
function __rtx_aliases
if test -z "$__rtx_aliases_cache"
set -g __rtx_aliases_cache (rtx alias ls | awk '{print $2}')
end
for a in $__rtx_aliases_cache
echo $a
end
end
function __rtx_settings
if test -z "$__rtx_settings_cache"
set -g __rtx_settings_cache (rtx settings ls | awk '{print $1}')
end
for s in $__rtx_settings_cache
echo $s
end
end
# vim: noet ci pi sts=0 sw=4 ts=4
6 changes: 3 additions & 3 deletions src/cli/settings/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ use crate::config::Config;
#[clap(after_long_help = AFTER_LONG_HELP, verbatim_doc_comment)]
pub struct SettingsGet {
/// The setting to show
pub key: String,
pub setting: String,
}

impl SettingsGet {
pub fn run(self, config: Config) -> Result<()> {
match config.settings.to_index_map().get(&self.key) {
match config.settings.to_index_map().get(&self.setting) {
Some(value) => Ok(rtxprintln!("{}", value)),
None => Err(eyre!("Unknown setting: {}", self.key)),
None => Err(eyre!("Unknown setting: {}", self.setting)),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/cli/settings/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use crate::config::Config;
pub struct SettingsSet {
/// The setting to set
#[clap()]
pub key: String,
pub setting: String,
/// The value to set
pub value: String,
}

impl SettingsSet {
pub fn run(self, mut config: Config) -> Result<()> {
let value: toml_edit::Value = match self.key.as_str() {
let value: toml_edit::Value = match self.setting.as_str() {
"experimental" => parse_bool(&self.value)?,
"always_keep_download" => parse_bool(&self.value)?,
"always_keep_install" => parse_bool(&self.value)?,
Expand All @@ -30,10 +30,10 @@ impl SettingsSet {
"shorthands_file" => self.value.into(),
"disable_default_shorthands" => parse_bool(&self.value)?,
"raw" => parse_bool(&self.value)?,
_ => return Err(eyre!("Unknown setting: {}", self.key)),
_ => return Err(eyre!("Unknown setting: {}", self.setting)),
};

config.global_config.update_setting(&self.key, value);
config.global_config.update_setting(&self.setting, value);
config.global_config.save()
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli/settings/unset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use crate::config::Config;
#[clap(visible_aliases = ["rm", "remove", "delete", "del"], after_long_help = AFTER_LONG_HELP, verbatim_doc_comment)]
pub struct SettingsUnset {
/// The setting to remove
pub key: String,
pub setting: String,
}

impl SettingsUnset {
pub fn run(self, mut config: Config) -> Result<()> {
config.global_config.remove_setting(&self.key);
config.global_config.remove_setting(&self.setting);
config.global_config.save()
}
}
Expand Down
19 changes: 18 additions & 1 deletion src/shell/completions/fish_complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ function __rtx_installed_tool_versions
echo $tv
end
end
function __rtx_aliases
if test -z "$__rtx_aliases_cache"
set -g __rtx_aliases_cache (rtx alias ls | awk '{{print $2}}')
end
for a in $__rtx_aliases_cache
echo $a
end
end
function __rtx_settings
if test -z "$__rtx_settings_cache"
set -g __rtx_settings_cache (rtx settings ls | awk '{{print $1}}')
end
for s in $__rtx_settings_cache
echo $s
end
end
# vim: noet ci pi sts=0 sw=4 ts=4
"#}
Expand Down Expand Up @@ -103,7 +119,8 @@ fn render_completer(a: &Arg) -> Option<String> {
"installed_tool" => Some("(__rtx_installed_tool_versions)".to_string()),
"plugin" => Some("(__rtx_plugins)".to_string()),
"new_plugin" => Some("(__rtx_all_plugins)".to_string()),
//"alias" => Some("(__rtx_aliases)".to_string()),
"alias" => Some("(__rtx_aliases)".to_string()),
"setting" => Some("(__rtx_settings)".to_string()),
//"prefix" => Some("(__rtx_prefixes)".to_string()),
_ => None,
},
Expand Down
6 changes: 6 additions & 0 deletions src/shell/completions/zsh_complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ pub fn render(cmd: &Command) -> String {
local -a aliases; aliases=($(rtx aliases ls ${{words[CURRENT-1]}} | awk '{{print $2}}'))
_describe -t aliases 'alias' aliases "$@"
}}
(( $+functions[__rtx_settings] )) ||
__rtx_settings() {{
local -a settings; settings=($(rtx settings ls | awk '{{print $1}}'))
_describe -t settings 'setting' settings "$@"
}}
(( $+functions[__rtx_prefixes] )) ||
__rtx_prefixes() {{
if [[ CURRENT -gt 2 ]]; then
Expand Down Expand Up @@ -228,6 +233,7 @@ fn render_completion(arg: &Arg) -> String {
"plugin" => "__rtx_plugins".to_string(),
"new_plugin" => "__rtx_all_plugins".to_string(),
"alias" => "__rtx_aliases".to_string(),
"setting" => "__rtx_settings".to_string(),
"prefix" => "__rtx_prefixes".to_string(),
_ => String::new(),
},
Expand Down

0 comments on commit fff00ef

Please sign in to comment.