Class: Soyuz::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/soyuz/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd) ⇒ Command

Returns a new instance of Command.

Raises:

  • (ArgumentError)


7
8
9
10
# File 'lib/soyuz/command.rb', line 7

def initialize(cmd)
  raise ArgumentError, "Command must be a string" unless cmd.is_a?(String)
  @cmd = cmd
end

Class Method Details

.build(cmd) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/soyuz/command.rb', line 12

def self.build(cmd)
  return if cmd.nil? || cmd.empty?

  if cmd.is_a?(Array)
    CommandChoice.new(cmd)
  elsif cmd.is_a?(Hash)
    CommandEnv.new(cmd)
  else
    new(cmd)
  end
end

Instance Method Details

#runObject



24
25
26
27
# File 'lib/soyuz/command.rb', line 24

def run
  say("<%= color('executing [#{@cmd}]...', :green) %>")
  exit(false) unless system(@cmd)
end