Class: Linecook::Commands::Command

Inherits:
Object
  • Object
show all
Extended by:
Lazydoc::Attributes
Includes:
Configurable
Defined in:
lib/linecook/commands/command.rb

Direct Known Subclasses

Build, Env, Helper, Init, Package, Run, VboxCommand

Constant Summary collapse

REGISTRY =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Command

Returns a new instance of Command.



29
30
31
32
# File 'lib/linecook/commands/command.rb', line 29

def initialize(config={})
  @quiet = true
  initialize_config(config)
end

Instance Attribute Details

#quietObject

Returns the value of attribute quiet.



27
28
29
# File 'lib/linecook/commands/command.rb', line 27

def quiet
  @quiet
end

Class Method Details

.inherited(base) ⇒ Object



12
13
14
15
# File 'lib/linecook/commands/command.rb', line 12

def inherited(base)
  super
  registry[base.to_s.split('::').last.downcase] = base
end

.registryObject



8
9
10
# File 'lib/linecook/commands/command.rb', line 8

def registry
  REGISTRY
end

Instance Method Details

#call(argv) ⇒ Object



49
50
51
# File 'lib/linecook/commands/command.rb', line 49

def call(argv)
  process(*argv)
end

#log(action, msg) ⇒ Object



34
35
36
# File 'lib/linecook/commands/command.rb', line 34

def log(action, msg)
  $stderr.puts("      %s  %s" % [action, msg])
end

#process(*args) ⇒ Object

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/linecook/commands/command.rb', line 53

def process(*args)
  raise NotImplementedError
end

#sh(cmd) ⇒ Object



38
39
40
41
# File 'lib/linecook/commands/command.rb', line 38

def sh(cmd)
  puts "% #{cmd}" unless quiet
  system(cmd)
end

#sh!(cmd) ⇒ Object



43
44
45
46
47
# File 'lib/linecook/commands/command.rb', line 43

def sh!(cmd)
  unless sh(cmd)
    raise CommandError.new("", $?.exitstatus)
  end
end