Class: Candelabra::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/candelabra/runner.rb

Overview

This class gives access to candelabra from the command line It has several useful functions like starting, stoping, and firing events to candelabra

Examples:

candelabra start
  # => I will let you guess what this one does

candelabra stop
  # => Yup it does that you are thinking

candelabra restart
  # => see above

candelabra event -e on_error
  # => send an error event to candelabra

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Runner

Set up the running for Candelabra. Parse out command and get all the data required for any command

Returns…it’s the initializer



25
26
27
28
29
# File 'lib/candelabra/runner.rb', line 25

def initialize(args)
  parse(args)
  @command = args.shift
  @data = args
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



19
20
21
# File 'lib/candelabra/runner.rb', line 19

def command
  @command
end

#configObject (readonly)

Returns the value of attribute config.



19
20
21
# File 'lib/candelabra/runner.rb', line 19

def config
  @config
end

#dataObject (readonly)

Returns the value of attribute data.



19
20
21
# File 'lib/candelabra/runner.rb', line 19

def data
  @data
end

#optionsObject (readonly)

Returns the value of attribute options.



19
20
21
# File 'lib/candelabra/runner.rb', line 19

def options
  @options
end

Instance Method Details



31
32
33
# File 'lib/candelabra/runner.rb', line 31

def banner
  Installer.get_template 'banner'
end

#parse(args) ⇒ Object

Take in the arguments from the command line and parse out any options and set up the options hash

Returns parsed optionr



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/candelabra/runner.rb', line 39

def parse( args )
  @options ={}
  Candelabra::Configuration.go do |config|
    OptionParser.new( args ) do |opts|
      opts.banner = banner 

      opts.on_tail( '-h', '--help', 'Show this message' ) do
        puts opts
        exit
      end

      opts.on_tail( '-v', '--version', 'Show Candelabra Version' ) do
        puts "Candelabra's Version is: #{ Candelabra::VERSION }"
        exit
      end

    end.parse!
  end

  Candelabra::Configuration.instance
end

#runObject

Execute the given command. Also fire off any events that occur in the system

Returns nothing special



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/candelabra/runner.rb', line 65

def run
  # here comes brute
  cmds = Remote.commands.keys.map{|x| x.to_s }.abbrev
  case command
  when 'start'
    Candelabra::Pianobar.start
  when 'stop'
    Candelabra::Pianobar.stop_all
  when 'restart'
    Candelabra::Pianobar.restart
  when 'flush' # Force flushing of the fifo files
    Candelabra::Remote.flush_all
  when 'install'
    Candelabra::Installer.run
  when *cmds.keys
    if data.nil? || data.empty?
      puts Remote.send cmds[command].to_sym
    else
      puts Remote.send cmds[command].to_sym, data
    end
  else
    puts "No command given"
  end
end