Skip to content

Commit

Permalink
env-vars: improvements
Browse files Browse the repository at this point in the history
* Use ui::table for better formatting
* Allow viewing a single env var with `mise ev FOO`
* Added --global flag

See #1432
  • Loading branch information
jdx committed Jan 11, 2024
1 parent 3d12e5a commit 2f1a9f1
Show file tree
Hide file tree
Showing 14 changed files with 225 additions and 185 deletions.
27 changes: 14 additions & 13 deletions completions/_mise
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ _mise() {
(direnv) __mise_direnv_cmd && ret=0 ;;
(doctor) __mise_doctor_cmd && ret=0 ;;
(e|env) __mise_env_cmd && ret=0 ;;
(ev|env-vars) __mise_env_vars_cmd && ret=0 ;;
(x|exec) __mise_exec_cmd && ret=0 ;;
(g|global) __mise_global_cmd && ret=0 ;;
(hook-env) __mise_hook_env_cmd && ret=0 ;;
Expand All @@ -46,6 +45,7 @@ _mise() {
(reshim) __mise_reshim_cmd && ret=0 ;;
(r|run) __mise_run_cmd && ret=0 ;;
(self-update) __mise_self_update_cmd && ret=0 ;;
(env-vars|ev|set) __mise_set_cmd && ret=0 ;;
(settings) __mise_settings_cmd && ret=0 ;;
(sh|shell) __mise_shell_cmd && ret=0 ;;
(sync) __mise_sync_cmd && ret=0 ;;
Expand Down Expand Up @@ -321,17 +321,6 @@ __mise_env_cmd() {
'*'{-v,--verbose}'[Show extra output (use -vv for even more)]' \
'(-y --yes)'{-y,--yes}'[Answer yes to all confirmation prompts]'
}
(( $+functions[__mise_env_vars_cmd] )) ||
__mise_env_vars_cmd() {
_arguments -s -S \
'--file=[The TOML file to update]:file:_files' \
'*--remove=[Remove the environment variable from config file]:remove:' \
'*::env_vars:' \
'(-C --cd)'{-C,--cd}'=[Change directory before running command]:cd:_directories' \
'(-q --quiet)'{-q,--quiet}'[Suppress non-error messages]' \
'*'{-v,--verbose}'[Show extra output (use -vv for even more)]' \
'(-y --yes)'{-y,--yes}'[Answer yes to all confirmation prompts]'
}
(( $+functions[__mise_exec_cmd] )) ||
__mise_exec_cmd() {
_arguments -s -S \
Expand Down Expand Up @@ -610,6 +599,18 @@ __mise_self_update_cmd() {
'(-q --quiet)'{-q,--quiet}'[Suppress non-error messages]' \
'*'{-v,--verbose}'[Show extra output (use -vv for even more)]'
}
(( $+functions[__mise_set_cmd] )) ||
__mise_set_cmd() {
_arguments -s -S \
'--file=[The TOML file to update]:file:_files' \
'(-g --global)'{-g,--global}'[Set the environment variable in the global config file]' \
'*--remove=[Remove the environment variable from config file]:remove:' \
'*::env_vars:' \
'(-C --cd)'{-C,--cd}'=[Change directory before running command]:cd:_directories' \
'(-q --quiet)'{-q,--quiet}'[Suppress non-error messages]' \
'*'{-v,--verbose}'[Show extra output (use -vv for even more)]' \
'(-y --yes)'{-y,--yes}'[Answer yes to all confirmation prompts]'
}
(( $+functions[__mise_settings_cmd] )) ||
__mise_settings_cmd() {
_arguments -s -S \
Expand Down Expand Up @@ -893,7 +894,6 @@ __mise_cmds() {
'direnv:Output direnv function to use mise inside direnv'
'doctor:Check mise installation for possible problems.'
{e,env}':Exports env vars to activate mise a single time'
{ev,env-vars}':Manage environment variables'
{x,exec}':Execute a command with tool(s) set'
'implode:Removes mise CLI and all related data'
{i,install}':Install a tool version'
Expand All @@ -907,6 +907,7 @@ __mise_cmds() {
'reshim:rebuilds the shim farm'
{r,run}':\[experimental\] Run a task'
'self-update:Updates mise itself'
'set:Manage environment variables'
'settings:Manage settings'
{sh,shell}':Sets a tool version for the current shell session'
'sync:Add tool versions from external tools to mise'
Expand Down
115 changes: 56 additions & 59 deletions completions/mise.bash
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ _mise() {
mise,env)
cmd="mise__env"
;;
mise,env-vars)
cmd="mise__env__vars"
;;
mise,ev)
cmd="mise__env__vars"
;;
mise,exec)
cmd="mise__exec"
;;
Expand Down Expand Up @@ -147,6 +141,9 @@ _mise() {
mise,self-update)
cmd="mise__self__update"
;;
mise,set)
cmd="mise__set"
;;
mise,settings)
cmd="mise__settings"
;;
Expand Down Expand Up @@ -348,9 +345,6 @@ _mise() {
mise__help,env)
cmd="mise__help__env"
;;
mise__help,env-vars)
cmd="mise__help__env__vars"
;;
mise__help,exec)
cmd="mise__help__exec"
;;
Expand Down Expand Up @@ -414,6 +408,9 @@ _mise() {
mise__help,self-update)
cmd="mise__help__self__update"
;;
mise__help,set)
cmd="mise__help__set"
;;
mise__help,settings)
cmd="mise__help__settings"
;;
Expand Down Expand Up @@ -700,7 +697,7 @@ _mise() {

case "${cmd}" in
mise)
opts="-C -q -v -y -h -V --debug --log-level --trace --cd --quiet --verbose --yes --help --version activate alias asdf bin-paths cache completion config current deactivate direnv doctor env env-vars exec global hook-env hook-not-found implode install latest link local ls ls-remote outdated plugins prune reshim run self-update settings shell sync task trust uninstall upgrade use version watch where which render-completion render-help render-mangen help"
opts="-C -q -v -y -h -V --debug --log-level --trace --cd --quiet --verbose --yes --help --version activate alias asdf bin-paths cache completion config current deactivate direnv doctor env exec global hook-env hook-not-found implode install latest link local ls ls-remote outdated plugins prune reshim run self-update set settings shell sync task trust uninstall upgrade use version watch where which render-completion render-help render-mangen help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -1589,40 +1586,6 @@ _mise() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
mise__env__vars)
opts="-C -q -v -y -h --file --remove --debug --log-level --trace --cd --quiet --verbose --yes --help [ENV_VARS]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
--file)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--remove)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--log-level)
COMPREPLY=($(compgen -W "error warn info debug trace" -- "${cur}"))
return 0
;;
--cd)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-C)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
mise__exec)
opts="-c -j -C -q -v -y -h --command --jobs --raw --debug --log-level --trace --cd --quiet --verbose --yes --help [TOOL@VERSION]... [COMMAND]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
Expand Down Expand Up @@ -1696,7 +1659,7 @@ _mise() {
return 0
;;
mise__help)
opts="activate alias asdf bin-paths cache completion config current deactivate direnv doctor env env-vars exec global hook-env hook-not-found implode install latest link local ls ls-remote outdated plugins prune reshim run self-update settings shell sync task trust uninstall upgrade use version watch where which render-completion render-help render-mangen help"
opts="activate alias asdf bin-paths cache completion config current deactivate direnv doctor env exec global hook-env hook-not-found implode install latest link local ls ls-remote outdated plugins prune reshim run self-update set settings shell sync task trust uninstall upgrade use version watch where which render-completion render-help render-mangen help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -2017,20 +1980,6 @@ _mise() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
mise__help__env__vars)
opts=""
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
mise__help__exec)
opts=""
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
Expand Down Expand Up @@ -2409,6 +2358,20 @@ _mise() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
mise__help__set)
opts=""
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
mise__help__settings)
opts="get ls set unset"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
Expand Down Expand Up @@ -3511,6 +3474,40 @@ _mise() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
mise__set)
opts="-g -C -q -v -y -h --file --global --remove --debug --log-level --trace --cd --quiet --verbose --yes --help [ENV_VARS]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
--file)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--remove)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--log-level)
COMPREPLY=($(compgen -W "error warn info debug trace" -- "${cur}"))
return 0
;;
--cd)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-C)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
mise__settings)
opts="-C -q -v -y -h --debug --log-level --trace --cd --quiet --verbose --yes --help get ls set unset help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
Expand Down
15 changes: 8 additions & 7 deletions completions/mise.fish
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ complete -kxc mise -s C -l cd -a "(__fish_complete_directories)" -d 'Change dire
complete -kxc mise -s q -l quiet -d 'Suppress non-error messages'
complete -kxc mise -s v -l verbose -d 'Show extra output (use -vv for even more)'
complete -kxc mise -s y -l yes -d 'Answer yes to all confirmation prompts'
set -l others activate alias bin-paths cache completion config current deactivate direnv doctor env env-vars exec implode install latest link ls ls-remote outdated plugins prune reshim run self-update settings shell sync task trust uninstall upgrade use version watch where which
set -l others activate alias bin-paths cache completion config current deactivate direnv doctor env exec implode install latest link ls ls-remote outdated plugins prune reshim run self-update set settings shell sync task trust uninstall upgrade use version watch where which
complete -xc mise -n "not $fssf $others" -a activate -d 'Initializes mise in the current shell session'
complete -xc mise -n "not $fssf $others" -a alias -d 'Manage aliases'
complete -xc mise -n "not $fssf $others" -a bin-paths -d 'List all the active runtime bin paths'
Expand All @@ -17,7 +17,6 @@ complete -xc mise -n "not $fssf $others" -a deactivate -d 'Disable mise for curr
complete -xc mise -n "not $fssf $others" -a direnv -d 'Output direnv function to use mise inside direnv'
complete -xc mise -n "not $fssf $others" -a doctor -d 'Check mise installation for possible problems.'
complete -xc mise -n "not $fssf $others" -a env -d 'Exports env vars to activate mise a single time'
complete -xc mise -n "not $fssf $others" -a env-vars -d 'Manage environment variables'
complete -xc mise -n "not $fssf $others" -a exec -d 'Execute a command with tool(s) set'
complete -xc mise -n "not $fssf $others" -a implode -d 'Removes mise CLI and all related data'
complete -xc mise -n "not $fssf $others" -a install -d 'Install a tool version'
Expand All @@ -31,6 +30,7 @@ complete -xc mise -n "not $fssf $others" -a prune -d 'Delete unused versions of
complete -xc mise -n "not $fssf $others" -a reshim -d 'rebuilds the shim farm'
complete -xc mise -n "not $fssf $others" -a run -d '[experimental] Run a task'
complete -xc mise -n "not $fssf $others" -a self-update -d 'Updates mise itself'
complete -xc mise -n "not $fssf $others" -a set -d 'Manage environment variables'
complete -xc mise -n "not $fssf $others" -a settings -d 'Manage settings'
complete -xc mise -n "not $fssf $others" -a shell -d 'Sets a tool version for the current shell session'
complete -xc mise -n "not $fssf $others" -a sync -d 'Add tool versions from external tools to mise'
Expand Down Expand Up @@ -121,11 +121,6 @@ complete -kxc mise -n "$fssf env" -s J -l json -d 'Output in JSON format'
complete -kxc mise -n "$fssf env" -s s -l shell -a "bash fish nu xonsh zsh" -d 'Shell type to generate environment variables for'
complete -kxc mise -n "$fssf env" -a "(__mise_tool_versions)" -d 'Tool(s) to use'
# env-vars
complete -kxc mise -n "$fssf env-vars" -d 'Environment variable(s) to set'
complete -kxc mise -n "$fssf env-vars" -l file -a "(__fish_complete_path)" -d 'The TOML file to update'
complete -kxc mise -n "$fssf env-vars" -l remove -d 'Remove the environment variable from config file'
# exec
complete -kxc mise -n "$fssf exec" -s c -l command -d 'Command string to execute'
complete -kxc mise -n "$fssf exec" -d 'Command string to execute (same as --command)'
Expand Down Expand Up @@ -238,6 +233,12 @@ complete -kxc mise -n "$fssf self-update" -l no-plugins -d 'Disable auto-updatin
complete -kxc mise -n "$fssf self-update" -d 'Update to a specific version'
complete -kxc mise -n "$fssf self-update" -s y -l yes -d 'Skip confirmation prompt'
# set
complete -kxc mise -n "$fssf set" -d 'Environment variable(s) to set'
complete -kxc mise -n "$fssf set" -l file -a "(__fish_complete_path)" -d 'The TOML file to update'
complete -kxc mise -n "$fssf set" -s g -l global -d 'Set the environment variable in the global config file'
complete -kxc mise -n "$fssf set" -l remove -d 'Remove the environment variable from config file'
# settings
set -l others get ls set unset
complete -xc mise -n "$fssf settings; and not $fssf $others" -a get -d 'Show a current setting'
Expand Down
68 changes: 39 additions & 29 deletions docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,35 +326,6 @@ Examples:
$ execx($(mise env -s xonsh))
```

## `mise env-vars [OPTIONS] [ENV_VARS]...`

**Aliases:** `ev`

```text
Manage environment variables
By default this command modifies ".mise.toml" in the current directory.
You can specify the file name by either setting the MISE_DEFAULT_CONFIG_FILENAME environment variable, or by using the --file option.
Usage: env-vars [OPTIONS] [ENV_VARS]...
Arguments:
[ENV_VARS]...
Environment variable(s) to set
e.g.: NODE_ENV=production
Options:
--file <FILE>
The TOML file to update
Defaults to MISE_DEFAULT_CONFIG_FILENAME environment variable, or ".mise.toml".
--remove <ENV_VAR>
Remove the environment variable from config file
Can be used multiple times.
```

## `mise exec [OPTIONS] [TOOL@VERSION]... [-- <COMMAND>...]`

**Aliases:** `x`
Expand Down Expand Up @@ -1007,6 +978,45 @@ Options:
Skip confirmation prompt
```

## `mise set [OPTIONS] [ENV_VARS]...`

```text
Manage environment variables
By default this command modifies ".mise.toml" in the current directory.
Usage: set [OPTIONS] [ENV_VARS]...
Arguments:
[ENV_VARS]...
Environment variable(s) to set
e.g.: NODE_ENV=production
Options:
--file <FILE>
The TOML file to update
Defaults to MISE_DEFAULT_CONFIG_FILENAME environment variable, or ".mise.toml".
-g, --global
Set the environment variable in the global config file
--remove <ENV_VAR>
Remove the environment variable from config file
Can be used multiple times.
Examples:
$ mise set NODE_ENV=production
$ mise set NODE_ENV
production
$ mise set
key value source
NODE_ENV production ~/.config/mise/config.toml
```

## `mise settings get <SETTING>`

```text
Expand Down
Loading

0 comments on commit 2f1a9f1

Please sign in to comment.