Class: BuckKnife::Command
- Inherits:
-
Object
- Object
- BuckKnife::Command
- Defined in:
- lib/buckknife/command.rb
Instance Method Summary collapse
- #arg(*args) ⇒ Object
- #escape(str) ⇒ Object
- #exec ⇒ Object
-
#initialize(cmd = "") ⇒ Command
constructor
A new instance of Command.
- #opt(*opts) ⇒ Object
- #to_s ⇒ Object
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 |
#exec ⇒ Object
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_s ⇒ Object
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 |