From 9094314883f23c06de6b1e4c3b2e8237797373c1 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdx@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:56:57 -0500 Subject: [PATCH] shell: fixed -h,--help flag --- src/cli/shell.rs | 2 +- src/shell/bash.rs | 12 +++++++----- src/shell/fish.rs | 19 +++++++++++++++---- .../rtx__shell__bash__tests__hook_init.snap | 12 +++++++----- ...tx__shell__bash__tests__hook_init_nix.snap | 12 +++++++----- .../rtx__shell__fish__tests__hook_init.snap | 19 +++++++++++++++---- ...tx__shell__fish__tests__hook_init_nix.snap | 19 +++++++++++++++---- .../rtx__shell__zsh__tests__hook_init.snap | 12 +++++++----- ...rtx__shell__zsh__tests__hook_init_nix.snap | 12 +++++++----- src/shell/zsh.rs | 12 +++++++----- 10 files changed, 88 insertions(+), 43 deletions(-) diff --git a/src/cli/shell.rs b/src/cli/shell.rs index 763190cda1..2738390eae 100644 --- a/src/cli/shell.rs +++ b/src/cli/shell.rs @@ -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)] diff --git a/src/shell/bash.rs b/src/shell/bash.rs index 977f378c0c..db3c5dbe2b 100644 --- a/src/shell/bash.rs +++ b/src/shell/bash.rs @@ -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() {{ diff --git a/src/shell/fish.rs b/src/shell/fish.rs index 61db98f655..a1400c4c64 100644 --- a/src/shell/fish.rs +++ b/src/shell/fish.rs @@ -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}; diff --git a/src/shell/snapshots/rtx__shell__bash__tests__hook_init.snap b/src/shell/snapshots/rtx__shell__bash__tests__hook_init.snap index cdd1d50f67..cdd27d9240 100644 --- a/src/shell/snapshots/rtx__shell__bash__tests__hook_init.snap +++ b/src/shell/snapshots/rtx__shell__bash__tests__hook_init.snap @@ -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() { diff --git a/src/shell/snapshots/rtx__shell__bash__tests__hook_init_nix.snap b/src/shell/snapshots/rtx__shell__bash__tests__hook_init_nix.snap index 790a2a9cb3..9e555f3cdb 100644 --- a/src/shell/snapshots/rtx__shell__bash__tests__hook_init_nix.snap +++ b/src/shell/snapshots/rtx__shell__bash__tests__hook_init_nix.snap @@ -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() { diff --git a/src/shell/snapshots/rtx__shell__fish__tests__hook_init.snap b/src/shell/snapshots/rtx__shell__fish__tests__hook_init.snap index 206d3b33e2..6b5021a3b6 100644 --- a/src/shell/snapshots/rtx__shell__fish__tests__hook_init.snap +++ b/src/shell/snapshots/rtx__shell__fish__tests__hook_init.snap @@ -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'; diff --git a/src/shell/snapshots/rtx__shell__fish__tests__hook_init_nix.snap b/src/shell/snapshots/rtx__shell__fish__tests__hook_init_nix.snap index 82f6744388..6d5fa03130 100644 --- a/src/shell/snapshots/rtx__shell__fish__tests__hook_init_nix.snap +++ b/src/shell/snapshots/rtx__shell__fish__tests__hook_init_nix.snap @@ -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'; diff --git a/src/shell/snapshots/rtx__shell__zsh__tests__hook_init.snap b/src/shell/snapshots/rtx__shell__zsh__tests__hook_init.snap index 7f0b514a3d..c6ebdde603 100644 --- a/src/shell/snapshots/rtx__shell__zsh__tests__hook_init.snap +++ b/src/shell/snapshots/rtx__shell__zsh__tests__hook_init.snap @@ -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() { diff --git a/src/shell/snapshots/rtx__shell__zsh__tests__hook_init_nix.snap b/src/shell/snapshots/rtx__shell__zsh__tests__hook_init_nix.snap index 891bf6245e..f1218f4b40 100644 --- a/src/shell/snapshots/rtx__shell__zsh__tests__hook_init_nix.snap +++ b/src/shell/snapshots/rtx__shell__zsh__tests__hook_init_nix.snap @@ -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() { diff --git a/src/shell/zsh.rs b/src/shell/zsh.rs index 1635584993..d600187567 100644 --- a/src/shell/zsh.rs +++ b/src/shell/zsh.rs @@ -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() {{