Skip to content

Commit

Permalink
shell: fixed -h,--help flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Nov 3, 2023
1 parent 5228fcf commit 9094314
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/cli/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::toolset::{ToolSource, ToolsetBuilder};
///
/// Only works in a session where rtx is already activated.
#[derive(Debug, clap::Args)]
#[clap(verbatim_doc_comment, after_long_help = AFTER_LONG_HELP)]
#[clap(verbatim_doc_comment, alias = "s", after_long_help = AFTER_LONG_HELP)]
pub struct Shell {
/// Tool(s) to use
#[clap(value_name="TOOL@VERSION", value_parser = ToolArgParser)]
Expand Down
12 changes: 7 additions & 5 deletions src/shell/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ impl Shell for Bash {
shift
case "$command" in
deactivate|shell)
eval "$(command rtx "$command" "$@")"
;;
*)
command rtx "$command" "$@"
deactivate|s|shell)
# if argv doesn't contains -h,--help
if [[ ! " $@ " =~ " --help " ]] && [[ ! " $@ " =~ " -h " ]]; then
eval "$(command rtx "$command" "$@")"
return $?
fi
;;
esac
command rtx "$command" "$@"
}}
_rtx_hook() {{
Expand Down
19 changes: 15 additions & 4 deletions src/shell/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,23 @@ impl Shell for Fish {
set command $argv[1]
set -e argv[1]
switch "$command"
case deactivate shell
source (command rtx "$command" $argv|psub)
case '*'
if contains -- --help $argv
command rtx "$command" $argv
return $status
end
switch "$command"
case deactivate s shell
# if help is requested, don't eval
if contains -- -h $argv
else if contains -- --help $argv
else
command rtx "$command" $argv | source
return $status
end
end
command rtx "$command" $argv
end
function __rtx_env_eval --on-event fish_prompt --description {description};
Expand Down
12 changes: 7 additions & 5 deletions src/shell/snapshots/rtx__shell__bash__tests__hook_init.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ rtx() {
shift

case "$command" in
deactivate|shell)
eval "$(command rtx "$command" "$@")"
;;
*)
command rtx "$command" "$@"
deactivate|s|shell)
# if argv doesn't contains -h,--help
if [[ ! " $@ " =~ " --help " ]] && [[ ! " $@ " =~ " -h " ]]; then
eval "$(command rtx "$command" "$@")"
return $?
fi
;;
esac
command rtx "$command" "$@"
}

_rtx_hook() {
Expand Down
12 changes: 7 additions & 5 deletions src/shell/snapshots/rtx__shell__bash__tests__hook_init_nix.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ rtx() {
shift

case "$command" in
deactivate|shell)
eval "$(command rtx "$command" "$@")"
;;
*)
command rtx "$command" "$@"
deactivate|s|shell)
# if argv doesn't contains -h,--help
if [[ ! " $@ " =~ " --help " ]] && [[ ! " $@ " =~ " -h " ]]; then
eval "$(command rtx "$command" "$@")"
return $?
fi
;;
esac
command rtx "$command" "$@"
}

_rtx_hook() {
Expand Down
19 changes: 15 additions & 4 deletions src/shell/snapshots/rtx__shell__fish__tests__hook_init.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,23 @@ function rtx
set command $argv[1]
set -e argv[1]

switch "$command"
case deactivate shell
source (command rtx "$command" $argv|psub)
case '*'
if contains -- --help $argv
command rtx "$command" $argv
return $status
end

switch "$command"
case deactivate s shell
# if help is requested, don't eval
if contains -- -h $argv
else if contains -- --help $argv
else
command rtx "$command" $argv | source
return $status
end
end

command rtx "$command" $argv
end

function __rtx_env_eval --on-event fish_prompt --description 'Update rtx environment when changing directories';
Expand Down
19 changes: 15 additions & 4 deletions src/shell/snapshots/rtx__shell__fish__tests__hook_init_nix.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,23 @@ function rtx
set command $argv[1]
set -e argv[1]

switch "$command"
case deactivate shell
source (command rtx "$command" $argv|psub)
case '*'
if contains -- --help $argv
command rtx "$command" $argv
return $status
end

switch "$command"
case deactivate s shell
# if help is requested, don't eval
if contains -- -h $argv
else if contains -- --help $argv
else
command rtx "$command" $argv | source
return $status
end
end

command rtx "$command" $argv
end

function __rtx_env_eval --on-event fish_prompt --description 'Update rtx environment when changing directories';
Expand Down
12 changes: 7 additions & 5 deletions src/shell/snapshots/rtx__shell__zsh__tests__hook_init.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ rtx() {
shift

case "$command" in
deactivate|shell)
eval "$(command rtx "$command" "$@")"
;;
*)
command rtx "$command" "$@"
deactivate|s|shell)
# if argv doesn't contains -h,--help
if [[ ! " $@ " =~ " --help " ]] && [[ ! " $@ " =~ " -h " ]]; then
eval "$(command rtx "$command" "$@")"
return $?
fi
;;
esac
command rtx "$command" "$@"
}

_rtx_hook() {
Expand Down
12 changes: 7 additions & 5 deletions src/shell/snapshots/rtx__shell__zsh__tests__hook_init_nix.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ rtx() {
shift

case "$command" in
deactivate|shell)
eval "$(command rtx "$command" "$@")"
;;
*)
command rtx "$command" "$@"
deactivate|s|shell)
# if argv doesn't contains -h,--help
if [[ ! " $@ " =~ " --help " ]] && [[ ! " $@ " =~ " -h " ]]; then
eval "$(command rtx "$command" "$@")"
return $?
fi
;;
esac
command rtx "$command" "$@"
}

_rtx_hook() {
Expand Down
12 changes: 7 additions & 5 deletions src/shell/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ impl Shell for Zsh {
shift
case "$command" in
deactivate|shell)
eval "$(command rtx "$command" "$@")"
;;
*)
command rtx "$command" "$@"
deactivate|s|shell)
# if argv doesn't contains -h,--help
if [[ ! " $@ " =~ " --help " ]] && [[ ! " $@ " =~ " -h " ]]; then
eval "$(command rtx "$command" "$@")"
return $?
fi
;;
esac
command rtx "$command" "$@"
}}
_rtx_hook() {{
Expand Down

0 comments on commit 9094314

Please sign in to comment.