Class: Candelabra::Runner
- Inherits:
-
Object
- Object
- Candelabra::Runner
- 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
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #banner ⇒ Object
-
#initialize(args) ⇒ Runner
constructor
Set up the running for Candelabra.
-
#parse(args) ⇒ Object
Take in the arguments from the command line and parse out any options and set up the options hash.
-
#run ⇒ Object
Execute the given command.
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
#command ⇒ Object (readonly)
Returns the value of attribute command.
19 20 21 |
# File 'lib/candelabra/runner.rb', line 19 def command @command end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
19 20 21 |
# File 'lib/candelabra/runner.rb', line 19 def config @config end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
19 20 21 |
# File 'lib/candelabra/runner.rb', line 19 def data @data end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
19 20 21 |
# File 'lib/candelabra/runner.rb', line 19 def @options end |
Instance Method Details
#banner ⇒ Object
31 32 33 |
# File 'lib/candelabra/runner.rb', line 31 def 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. = 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 |
#run ⇒ Object
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 |