Class: Chore::CLI
Overview
Class that handles the command line interactions in Chore. It primarily is responsible for invoking the Chore process with the provided configuration to begin processing jobs.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#registered_opts ⇒ Object
readonly
Returns the value of attribute registered_opts.
Class Method Summary collapse
-
.register_option(key, *args, &blk) ⇒ Object
register_option
is a method for plugins or other components to register command-line config options.
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
-
#parse(args = ARGV) ⇒ Object
:nodoc:.
-
#parse_config_file(file, ignore_errors = false) ⇒ Object
:nodoc:.
-
#register_option(key, *args, &blk) ⇒ Object
:nodoc:.
-
#run!(args = ARGV) ⇒ Object
Start up the consuming side of the application.
-
#shutdown ⇒ Object
Begins the Chore shutdown process.
Methods included from Util
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
21 22 23 24 25 |
# File 'lib/chore/cli.rb', line 21 def initialize @options = {} @registered_opts = {} @stopping = false end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
19 20 21 |
# File 'lib/chore/cli.rb', line 19 def @options end |
#registered_opts ⇒ Object (readonly)
Returns the value of attribute registered_opts.
19 20 21 |
# File 'lib/chore/cli.rb', line 19 def registered_opts @registered_opts end |
Class Method Details
.register_option(key, *args, &blk) ⇒ Object
register_option
is a method for plugins or other components to
register command-line config options.
-
key
is the name for this option that can be referenced from Chore.config.key
-
*args
is anOptionParser
style list of options. -
&blk
is an option block, passed toOptionParser
Examples
Chore::CLI.register_option 'sample', '-s', '--sample-key SOME_VAL', 'A description of this value'
Chore::CLI.register_option 'something', '-g', '--something-complex VALUE', 'A description' do |arg|
# make sure your key here matches the key you register
options[:something] arg.split(',')
end
40 41 42 |
# File 'lib/chore/cli.rb', line 40 def self.register_option(key,*args,&blk) instance.register_option(key,*args,&blk) end |
Instance Method Details
#parse(args = ARGV) ⇒ Object
:nodoc:
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/chore/cli.rb', line 72 def parse(args=ARGV) #:nodoc: Chore.configuring = true # parse once to load the config file & require options # any invalid options are ignored the first time around since booting the # system may register additional options from 3rd-party libs parse_opts(args, true) parse_config_file(@options[:config_file], true) if @options[:config_file] validate! boot_system # parse again to pick up options required by loaded classes # any invalid options will raise an exception this time parse_opts(args) parse_config_file(@options[:config_file]) if @options[:config_file] detect_queues Chore.configure() Chore.configuring = false validate_strategy! end |
#parse_config_file(file, ignore_errors = false) ⇒ Object
:nodoc:
66 67 68 69 70 |
# File 'lib/chore/cli.rb', line 66 def parse_config_file(file, ignore_errors = false) #:nodoc: data = File.read(file) data = ERB.new(data).result parse_opts(data.split(/\s/).map!(&:chomp).map!(&:strip), ignore_errors) end |
#register_option(key, *args, &blk) ⇒ Object
:nodoc:
44 45 46 47 |
# File 'lib/chore/cli.rb', line 44 def register_option(key,*args,&blk) #:nodoc: registered_opts[key] = {:args => args} registered_opts[key].merge!(:block => blk) if blk end |
#run!(args = ARGV) ⇒ Object
Start up the consuming side of the application. This calls Chore::Manager#start.
50 51 52 53 54 |
# File 'lib/chore/cli.rb', line 50 def run!(args=ARGV) parse(args) @manager = Chore::Manager.new @manager.start end |
#shutdown ⇒ Object
Begins the Chore shutdown process. This will call Chore::Manager#shutdown if it is not already in the process of stopping Exits with code 0
58 59 60 61 62 63 64 |
# File 'lib/chore/cli.rb', line 58 def shutdown unless @stopping @stopping = true @manager.shutdown! if @manager exit(0) end end |