Method: TTY::Command::Cmd#initialize
- Defined in:
- lib/tty/command/cmd.rb
#initialize(env_or_cmd, *args) ⇒ Cmd
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a new Cmd object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/tty/command/cmd.rb', line 34 def initialize(env_or_cmd, *args) opts = args.last.respond_to?(:to_hash) ? args.pop : {} if env_or_cmd.respond_to?(:to_hash) @env = env_or_cmd unless command = args.shift raise ArgumentError, "Cmd requires command argument" end else command = env_or_cmd end if args.empty? && cmd = command.to_s raise ArgumentError, "No command provided" if cmd.empty? @command = sanitize(cmd) @argv = [] else if command.respond_to?(:to_ary) @command = sanitize(command[0]) args.unshift(*command[1..-1]) else @command = sanitize(command) end @argv = args.map { |i| Shellwords.escape(i) } end @env ||= {} = opts @uuid = SecureRandom.uuid.split("-")[0] @only_output_on_error = opts.fetch(:only_output_on_error) { false } freeze end |