Module: RVM::Shell::Utility
- Included in:
- AbstractWrapper
- Defined in:
- lib/rvm/shell/utility.rb
Instance Method Summary collapse
-
#build_cli_call(command, args = nil) ⇒ Object
From a command, will build up a runnable command.
-
#escape_argument(s) ⇒ Object
Given a string, converts to the escaped format.
-
#escape_arguments(*args) ⇒ Object
Takes an array / number of arguments and converts them to a string useable for passing into a shell call.
Instance Method Details
#build_cli_call(command, args = nil) ⇒ Object
From a command, will build up a runnable command. If args isn’t provided, it will escape arguments.
31 32 33 |
# File 'lib/rvm/shell/utility.rb', line 31 def build_cli_call(command, args = nil) "#{command} #{escape_arguments(args)}".strip end |
#escape_argument(s) ⇒ Object
Given a string, converts to the escaped format. This ensures that things such as variables aren’t evaluated into strings and everything else is setup as expected.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rvm/shell/utility.rb', line 17 def escape_argument(s) return "''" if s.empty? s.scan(/('+|[^']+)/).map do |section| section = section.first if section[0] == ?' "\\'" * section.length else "'#{section}'" end end.join end |
#escape_arguments(*args) ⇒ Object
Takes an array / number of arguments and converts them to a string useable for passing into a shell call.
9 10 11 12 |
# File 'lib/rvm/shell/utility.rb', line 9 def escape_arguments(*args) return '' if args.nil? args.flatten.map { |a| escape_argument(a.to_s) }.join(" ") end |