lib/rzo/option_parsing.rb in rzo-0.3.0 vs lib/rzo/option_parsing.rb in rzo-0.4.0

- old
+ new

@@ -45,24 +45,28 @@ # Modifies argv as a side effect, shifting elements from the array until # the first unknown option is found, which is assumed to be the subcommand # name. # # @return [Hash<Symbol, String>] Global options - # rubocop:disable Metrics/MethodLength + # rubocop:disable Metrics/MethodLength, Metrics/AbcSize def parse_global_options!(argv, env) semver = Rzo::VERSION prog_name = NAME Rzo::Trollop.options(argv) do stop_on_unknown version "#{prog_name} #{semver} (c) 2017 Garrett Honeycutt" banner BANNER log_msg = 'Log file to write to or keywords '\ 'STDOUT, STDERR {RZO_LOGTO}' opt :logto, log_msg, default: env['RZO_LOGTO'] || 'STDERR' + opt :validate, 'Check the configuration for common issues {RZO_VALIDATE="false"}', + default: env['RZO_VALIDATE'] == 'false' ? false : true opt :syslog, 'Log to syslog', default: false, conflicts: :logto - opt :verbose, 'Set log level to INFO' - opt :debug, 'Set log level to DEBUG' + opt :verbose, 'Set log level to INFO {RZO_VERBOSE="true"}', + default: env['RZO_VERBOSE'] == 'true' + opt :debug, 'Set log level to DEBUG {RZO_DEBUG="true"}', + default: env['RZO_DEBUG'] == 'true' opt :config, 'Rizzo config file {RZO_CONFIG}', default: env['RZO_CONFIG'] || '~/.rizzo.json' end end # rubocop:enable Metrics/MethodLength, Metrics/AbcSize @@ -84,11 +88,11 @@ # # Modifies argv as a side effect, shifting all options as things are # parsed. # # @return [Hash<Symbol, String>] Subcommand specific options hash - # rubocop:disable Metrics/MethodLength + # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity def parse_subcommand_options!(subcommand, argv, env) prog_name = NAME case subcommand when 'config' Rzo::Trollop.options(argv) do @@ -98,15 +102,20 @@ when 'generate' Rzo::Trollop.options(argv) do banner "#{prog_name} #{subcommand} options:" opt :vagrantfile, 'Output Vagrantfile', short: 'o', default: env['RZO_VAGRANTFILE'] || 'Vagrantfile' end + when 'roles' + Rzo::Trollop.options(argv) do + banner "#{prog_name} #{subcommand} options:" + opt :output, 'Roles output', short: 'o', default: env['RZO_OUTPUT'] || 'STDOUT' + end else Rzo::Trollop.die "Unknown subcommand: #{subcommand.inspect}" end end - # rubocop:enable Metrics/MethodLength, Metrics/AbcSize + # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity # The name of the executable, could be `rizzo` or `rzo` NAME = File.basename($PROGRAM_NAME).freeze # rubocop:disable Layout/IndentHeredoc @@ -114,9 +123,10 @@ usage: #{NAME} [GLOBAL OPTIONS] SUBCOMMAND [ARGS] Sub Commands: config Print out the combined rizzo json config generate Initialize Vagrantfile in top control repo + roles Output all roles defined in the combined config Global options: (Note, command line arguments supersede ENV vars in {}'s) EOBANNER end end