Class: Clinode::Command
- Includes:
- FileUtils
- Defined in:
- lib/clinode/command.rb
Defined Under Namespace
Classes: Shell
Instance Method Summary collapse
- #call(*args) ⇒ Object
- #current_user?(user) ⇒ Boolean
- #die(message) ⇒ Object
- #helper ⇒ Object
- #highline ⇒ Object
-
#initialize(block) ⇒ Command
constructor
A new instance of Command.
- #options ⇒ Object
- #run(method, command) ⇒ Object
- #sh(*command) ⇒ Object
- #shell_user ⇒ Object
Constructor Details
#initialize(block) ⇒ Command
Returns a new instance of Command.
18 19 20 |
# File 'lib/clinode/command.rb', line 18 def initialize(block) (class << self;self end).send :define_method, :command, &block end |
Instance Method Details
#call(*args) ⇒ Object
22 23 24 25 26 |
# File 'lib/clinode/command.rb', line 22 def call(*args) arity = method(:command).arity args << nil while args.size < arity send :command, *args end |
#current_user?(user) ⇒ Boolean
63 64 65 |
# File 'lib/clinode/command.rb', line 63 def current_user?(user) user == shell_user end |
#die(message) ⇒ Object
50 51 52 53 |
# File 'lib/clinode/command.rb', line 50 def die() puts "=> #{}" exit! end |
#helper ⇒ Object
28 29 30 |
# File 'lib/clinode/command.rb', line 28 def helper @helper ||= Helper.new end |
#highline ⇒ Object
55 56 57 |
# File 'lib/clinode/command.rb', line 55 def highline @highline ||= HighLine.new end |
#run(method, command) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/clinode/command.rb', line 36 def run(method, command) if command.is_a? Array command = [ 'git', command ].flatten else command = 'git ' + command end send method, *command end |
#sh(*command) ⇒ Object
46 47 48 |
# File 'lib/clinode/command.rb', line 46 def sh(*command) Shell.new(*command).run end |
#shell_user ⇒ Object
59 60 61 |
# File 'lib/clinode/command.rb', line 59 def shell_user ENV['USER'] end |