From 8fabc56a22d8ba53ecb26a9d4a9916ec849593c9 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 10 Oct 2020 15:31:32 +0200 Subject: [PATCH] Inline type annotations for `Utils::Shell`. --- Library/Homebrew/sorbet/rbi/utils/shell.rbi | 38 --------------------- Library/Homebrew/utils/shell.rb | 20 ++++++++--- 2 files changed, 16 insertions(+), 42 deletions(-) delete mode 100644 Library/Homebrew/sorbet/rbi/utils/shell.rbi diff --git a/Library/Homebrew/sorbet/rbi/utils/shell.rbi b/Library/Homebrew/sorbet/rbi/utils/shell.rbi deleted file mode 100644 index f4a3507bd8..0000000000 --- a/Library/Homebrew/sorbet/rbi/utils/shell.rbi +++ /dev/null @@ -1,38 +0,0 @@ -# typed: strict - -module Utils::Shell - include Kernel - - sig{ params(path: String).returns(T.nilable(Symbol)) } - def from_path(path) - end - - sig{ returns(T.nilable(Symbol)) } - def preferred - end - - def parent - end - - def export_value(key, value, shell = preferred) - end - - sig{ returns(String) } - def profile - end - - def set_variable_in_profile(variable, value) - end - - sig{ params(path: String).returns(T.nilable(String)) } - def prepend_path_in_profile(path) - end - - sig{ params(str: String).returns(T.nilable(String)) } - def csh_quote(str) - end - - sig{ params(str: String).returns(T.nilable(String)) } - def sh_quote(str) - end -end diff --git a/Library/Homebrew/utils/shell.rb b/Library/Homebrew/utils/shell.rb index 4d9af01ff1..c469c3ad94 100644 --- a/Library/Homebrew/utils/shell.rb +++ b/Library/Homebrew/utils/shell.rb @@ -3,10 +3,14 @@ module Utils module Shell + include Kernel + extend T::Sig + module_function - # take a path and heuristically convert it - # to a shell name, return nil if there's no match + # Take a path and heuristically convert it to a shell name, + # return `nil` if there's no match. + sig { params(path: String).returns(T.nilable(Symbol)) } def from_path(path) # we only care about the basename shell_name = File.basename(path) @@ -15,15 +19,18 @@ module Utils shell_name.to_sym if %w[bash csh fish ksh mksh sh tcsh zsh].include?(shell_name) end + sig { returns(T.nilable(Symbol)) } def preferred from_path(ENV.fetch("SHELL", "")) end + sig { returns(T.nilable(Symbol)) } def parent from_path(`ps -p #{Process.ppid} -o ucomm=`.strip) end - # quote values. quoting keys is overkill + # Quote values. Quoting keys is overkill. + sig { params(key: String, value: String, shell: T.nilable(Symbol)).returns(T.nilable(String)) } def export_value(key, value, shell = preferred) case shell when :bash, :ksh, :mksh, :sh, :zsh @@ -38,7 +45,8 @@ module Utils end end - # return the shell profile file based on user's preferred shell + # Return the shell profile file based on user's preferred shell. + sig { returns(String) } def profile case preferred when :bash @@ -51,6 +59,7 @@ module Utils SHELL_PROFILE_MAP.fetch(preferred, "~/.profile") end + sig { params(variable: String, value: String).returns(T.nilable(String)) } def set_variable_in_profile(variable, value) case preferred when :bash, :ksh, :sh, :zsh, nil @@ -62,6 +71,7 @@ module Utils end end + sig { params(path: String).returns(T.nilable(String)) } def prepend_path_in_profile(path) case preferred when :bash, :ksh, :mksh, :sh, :zsh, nil @@ -86,6 +96,7 @@ module Utils UNSAFE_SHELL_CHAR = %r{([^A-Za-z0-9_\-.,:/@~\n])}.freeze + sig { params(str: String).returns(String) } def csh_quote(str) # ruby's implementation of shell_escape str = str.to_s @@ -99,6 +110,7 @@ module Utils str end + sig { params(str: String).returns(String) } def sh_quote(str) # ruby's implementation of shell_escape str = str.to_s