Sha256: 821970c3ba10196395f5b30bf0b7a27da1aa5d9bcb2094a3a4d39a5e9f6f39af

Contents?: true

Size: 1.02 KB

Versions: 107

Compression:

Stored size: 1.02 KB

Contents

module RVM
  module Shell
    module Utility

      public

      # Takes an array / number of arguments and converts
      # them to a string useable for passing into a shell call.
      def escape_arguments(*args)
        return '' if args.nil?
        args.flatten.map { |a| escape_argument(a.to_s) }.join(" ")
      end

      # 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.
      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

      # From a command, will build up a runnable command. If args isn't provided,
      # it will escape arguments.
      def build_cli_call(command, args = nil)
        "#{command} #{escape_arguments(args)}".strip
      end

    end
  end
end

Version data entries

107 entries across 107 versions & 2 rubygems

Version Path
rvm-1.11.3.9 lib/rvm/shell/utility.rb
rvm-1.11.3.8 lib/rvm/shell/utility.rb
rvm-1.11.3.7 lib/rvm/shell/utility.rb
rvm-1.11.3.6 lib/rvm/shell/utility.rb
rvm-1.11.3.5 lib/rvm/shell/utility.rb
rvm-1.11.3.4 lib/rvm/shell/utility.rb
rvm-1.11.3.3 lib/rvm/shell/utility.rb
rvm-1.11.3.2 lib/rvm/shell/utility.rb
rvm-1.11.3.1 lib/rvm/shell/utility.rb
rvm-1.11.3 lib/rvm/shell/utility.rb
rvm-1.9.2 lib/rvm/shell/utility.rb
rvm-1.9.1 lib/rvm/shell/utility.rb
rvm-1.9.0 lib/rvm/shell/utility.rb
rvm-1.8.6 lib/rvm/shell/utility.rb
rvm-1.8.5 lib/rvm/shell/utility.rb
rvm-1.8.4 lib/rvm/shell/utility.rb
rvm-1.8.3 lib/rvm/shell/utility.rb
rvm-1.8.2 lib/rvm/shell/utility.rb
rvm-1.8.1 lib/rvm/shell/utility.rb
rvm-1.7.0 lib/rvm/shell/utility.rb