Class: BuckKnife::Command

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

Instance Method Summary collapse

Constructor Details

#initialize(cmd = "") ⇒ Command

Returns a new instance of Command.



5
6
7
8
# File 'lib/buckknife/command.rb', line 5

def initialize(cmd="")
  @cmd = cmd
  @args, @opts = [], []
end

Instance Method Details

#arg(*args) ⇒ Object



10
11
12
13
# File 'lib/buckknife/command.rb', line 10

def arg(*args)
  @args += args
  self
end

#escape(str) ⇒ Object



29
30
31
# File 'lib/buckknife/command.rb', line 29

def escape(str)
  Escape.shell_single_word(str).to_s
end

#execObject



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

def exec
  `#{self.to_s}`
end

#opt(*opts) ⇒ Object



15
16
17
18
# File 'lib/buckknife/command.rb', line 15

def opt(*opts)
  @opts += opts
  self
end

#to_sObject



20
21
22
# File 'lib/buckknife/command.rb', line 20

def to_s
  [ @cmd ].concat(@args).concat(@opts).map(&:to_s).map { |w| escape(w) }.join(' ')
end