Class: Daemon::Command::Options
- Inherits:
-
Object
- Object
- Daemon::Command::Options
- Includes:
- UserInterface
- Defined in:
- lib/onapp/engine/command/options.rb
Overview
Parses ARGV and provides some options through attribute-accessors
Constant Summary
- DEFAULT_DAEMONS_COUNT =
1
Instance Attribute Summary (collapse)
-
- (Object) command
Returns the value of attribute command.
-
- (Object) forced
Returns the value of attribute forced.
-
- (Object) forked
Returns the value of attribute forked.
-
- (Object) only_instances
Returns the value of attribute only_instances.
Attributes included from UserInterface
Instance Method Summary (collapse)
-
- (Options) initialize(argv, out = $stdout, err = $stderr)
constructor
A new instance of Options.
-
- (Object) parse!
Validates and parses ARGV.
Methods included from UserInterface
Constructor Details
- (Options) initialize(argv, out = $stdout, err = $stderr)
Returns a new instance of Options
16 17 18 19 20 21 22 23 24 |
# File 'lib/onapp/engine/command/options.rb', line 16 def initialize(argv, out = $stdout, err = $stderr) @argv = argv.dup @out = out @err = err @forked = true @only_instances = false @forced = false end |
Instance Attribute Details
- (Object) command
Returns the value of attribute command
11 12 13 |
# File 'lib/onapp/engine/command/options.rb', line 11 def command @command end |
- (Object) forced
Returns the value of attribute forced
11 12 13 |
# File 'lib/onapp/engine/command/options.rb', line 11 def forced @forced end |
- (Object) forked
Returns the value of attribute forked
11 12 13 |
# File 'lib/onapp/engine/command/options.rb', line 11 def forked @forked end |
- (Object) only_instances
Returns the value of attribute only_instances
11 12 13 |
# File 'lib/onapp/engine/command/options.rb', line 11 def only_instances @only_instances end |
Instance Method Details
- (Object) parse!
Validates and parses ARGV
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/onapp/engine/command/options.rb', line 29 def parse! parser = OptionParser.new do |opts| opts. = "Usage: #{$0} #{COMMANDS.join('|')}" opts.separator 'Options:' opts.on '-f', '--[no-]fork', 'Fork and detach' do |v| @forked = v end opts.on '-F', '--force', 'Force stop' do |v| @forced = v end opts.on '-o', '--only-instances', 'Stop only instances, don\'t kill master' do |v| @only_instances = v end opts.on_tail '-h', '--help', 'Show this message' do say parser return false end end parser.parse!(@argv) @command = @argv[0] if @argv.length == 0 || @argv.length > 1 || !Daemon::Command::COMMANDS.include?(@command) error "Wrong command: #{@argv.join(' ')}" error parser return false end true rescue OptionParser::ParseError => ex error ex. error parser return false end |