Class: Epi::Cli::Command

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Command

Returns a new instance of Command.



18
19
20
# File 'lib/epi/cli/command.rb', line 18

def initialize(args)
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



16
17
18
# File 'lib/epi/cli/command.rb', line 16

def args
  @args
end

Class Method Details

.run(command, args) ⇒ Object

Raises:



7
8
9
10
11
12
13
14
# File 'lib/epi/cli/command.rb', line 7

def self.run(command, args)
  const_name = command.camelize.to_sym
  if Commands.const_defined? const_name
    klass = Commands.const_get const_name
    return klass.new(args).run if Class === klass && klass < self
  end
  raise Exceptions::Fatal, 'Unknown command'
end

Instance Method Details

#need_root!Object

Raises:



22
23
24
25
26
# File 'lib/epi/cli/command.rb', line 22

def need_root!
  process = Epi::Daemon.process
  raise Exceptions::Fatal, 'You need root privileges to manage this daemon' if
      process && process.was_alive? && process.root? && !Epi.root?
end