Class: Clinode::Command

Inherits:
Object show all
Includes:
FileUtils
Defined in:
lib/clinode/command.rb

Defined Under Namespace

Classes: Shell

Instance Method Summary collapse

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

Returns:

  • (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(message)
  puts "=> #{message}"
  exit!
end

#helperObject



28
29
30
# File 'lib/clinode/command.rb', line 28

def helper
  @helper ||= Helper.new
end

#highlineObject



55
56
57
# File 'lib/clinode/command.rb', line 55

def highline
  @highline ||= HighLine.new
end

#optionsObject



32
33
34
# File 'lib/clinode/command.rb', line 32

def options
  Clinode.options
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_userObject



59
60
61
# File 'lib/clinode/command.rb', line 59

def shell_user
  ENV['USER']
end