Class: AppStack::CliOptions
- Inherits:
-
Object
- Object
- AppStack::CliOptions
- Defined in:
- lib/app_stack/cli_options.rb
Overview
parse command line options based rubocop:disable MethodLength
Instance Attribute Summary collapse
-
#conf_file ⇒ Object
Returns the value of attribute conf_file.
-
#force ⇒ Object
Returns the value of attribute force.
-
#recursive ⇒ Object
Returns the value of attribute recursive.
-
#simulate ⇒ Object
Returns the value of attribute simulate.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#initialize(argv = ARGV) ⇒ CliOptions
constructor
A new instance of CliOptions.
-
#parse_opt!(argv) ⇒ Object
parse command line options.
Constructor Details
#initialize(argv = ARGV) ⇒ CliOptions
Returns a new instance of CliOptions.
11 12 13 14 15 16 17 18 |
# File 'lib/app_stack/cli_options.rb', line 11 def initialize(argv = ARGV) parse_opt!(argv) case argv.size when 1 then self.conf_file = argv.shift when 0 then self.conf_file = nil else fail "too many configuration files (#{argv.join(', ')})." end end |
Instance Attribute Details
#conf_file ⇒ Object
Returns the value of attribute conf_file.
9 10 11 |
# File 'lib/app_stack/cli_options.rb', line 9 def conf_file @conf_file end |
#force ⇒ Object
Returns the value of attribute force.
9 10 11 |
# File 'lib/app_stack/cli_options.rb', line 9 def force @force end |
#recursive ⇒ Object
Returns the value of attribute recursive.
9 10 11 |
# File 'lib/app_stack/cli_options.rb', line 9 def recursive @recursive end |
#simulate ⇒ Object
Returns the value of attribute simulate.
9 10 11 |
# File 'lib/app_stack/cli_options.rb', line 9 def simulate @simulate end |
#verbose ⇒ Object
Returns the value of attribute verbose.
9 10 11 |
# File 'lib/app_stack/cli_options.rb', line 9 def verbose @verbose end |
Instance Method Details
#parse_opt!(argv) ⇒ Object
parse command line options
21 22 23 24 25 26 27 28 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 |
# File 'lib/app_stack/cli_options.rb', line 21 def parse_opt!(argv) opt_parser = OptionParser.new do |opts| opts. = 'Usage: appstack [options] [config_file]' opts.separator '' opts.separator 'Available options:' opts.on('-f', '--force', 'force overwrite') do self.force = true end opts.on('-s', '--simulate', 'simulate only, do not copy') do self.simulate = true end opts.on('-r', '--recursive', 'recursively stackup all apps') do self.recursive = true end opts.on('--verbose', 'show debug messages') do self.verbose = true end opts.on_tail('-h', '--help', 'show this message') do puts opts exit end opts.on_tail('-v', '--version', 'show version number') do puts AppStack::VERSION exit end end opt_parser.parse!(argv) end |