Skip to content

Commit

Permalink
shell: fixed -h,--help flag (#976)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored Nov 8, 2023
1 parent 231e1d0 commit 8ec558a
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 37 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
16 changes: 14 additions & 2 deletions src/shell/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,21 @@ impl Shell for Fish {
set command $argv[1]
set -e argv[1]
if contains -- --help $argv
command rtx "$command" $argv
return $status
end
switch "$command"
case deactivate shell
source (command rtx "$command" $argv|psub)
case deactivate s shell
# if help is requested, don't eval
if contains -- -h $argv
command rtx "$command" $argv
else if contains -- --help $argv
command rtx "$command" $argv
else
source (command rtx "$command" $argv |psub)
end
case '*'
command rtx "$command" $argv
end
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
16 changes: 14 additions & 2 deletions src/shell/snapshots/rtx__shell__fish__tests__hook_init.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,21 @@ function rtx
set command $argv[1]
set -e argv[1]

if contains -- --help $argv
command rtx "$command" $argv
return $status
end

switch "$command"
case deactivate shell
source (command rtx "$command" $argv|psub)
case deactivate s shell
# if help is requested, don't eval
if contains -- -h $argv
command rtx "$command" $argv
else if contains -- --help $argv
command rtx "$command" $argv
else
source (command rtx "$command" $argv |psub)
end
case '*'
command rtx "$command" $argv
end
Expand Down
16 changes: 14 additions & 2 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,9 +13,21 @@ function rtx
set command $argv[1]
set -e argv[1]

if contains -- --help $argv
command rtx "$command" $argv
return $status
end

switch "$command"
case deactivate shell
source (command rtx "$command" $argv|psub)
case deactivate s shell
# if help is requested, don't eval
if contains -- -h $argv
command rtx "$command" $argv
else if contains -- --help $argv
command rtx "$command" $argv
else
source (command rtx "$command" $argv |psub)
end
case '*'
command rtx "$command" $argv
end
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 8ec558a

Please sign in to comment.