Class: AppStack::CliOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/app_stack/cli_options.rb

Overview

parse command line options based rubocop:disable MethodLength

Instance Attribute Summary collapse

Instance Method Summary collapse

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_fileObject

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

#forceObject

Returns the value of attribute force.



9
10
11
# File 'lib/app_stack/cli_options.rb', line 9

def force
  @force
end

#recursiveObject

Returns the value of attribute recursive.



9
10
11
# File 'lib/app_stack/cli_options.rb', line 9

def recursive
  @recursive
end

#simulateObject

Returns the value of attribute simulate.



9
10
11
# File 'lib/app_stack/cli_options.rb', line 9

def simulate
  @simulate
end

#verboseObject

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.banner = '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