lib/bolt/cli.rb
# Parses the command and validates options. All errors that are raised here
# are not handled by the outputter, as it relies on config being loaded.
Parses the command and validates options. All errors that are raised here
are not handled by the outputter, as it relies on config being loaded.
Parses the command and validates options . All errors that are raised here are not handled by the outputter as it relies on config being loaded .
def parse_command
      parser = BoltOptionParser.new(options)
      remaining = handle_parser_errors { parser.permute(@argv) } unless @argv.empty?
      if @argv.empty? || help?(remaining)
        parser.update
        puts parser.help
        raise Bolt::CLIExit
      end
      options[:object] = remaining.shift
      if %w[task plan].include?(options[:subcommand])
        task_options, remaining = remaining.partition { |s| s =~ /.+=/ }
        if options[:task_options]
          unless task_options.empty?
            raise Bolt::CLIError,
                  "Parameters must be specified through either the --params " \
                  "option or param=value pairs, not both"
          end
          options[:params_parsed] = true
        elsif task_options.any?
          options[:params_parsed] = false
          options[:task_options] = Hash[task_options.map { |a| a.split('=', 2) }]
        else
          options[:params_parsed] = true
          options[:task_options] = {}
        end
      end
      options[:leftovers] = remaining
      unless options.key?(:verbose)
        options[:verbose] = options[:subcommand] != 'plan'
      end
      validate(options)
      @parser_deprecations = parser.deprecations
    rescue Bolt::Error => e
      fatal_error(e)
      raise e
    end
def parse_command parser = BoltOptionParser . new ( options ) remaining = handle_parser_errors { parser . permute ( @argv ) } unless @argv . empty? if @argv . empty? || help? ( remaining ) parser . update puts parser . help raise Bolt :: CLIExit end options [ :object ] = remaining . shift if %w[ task plan ] . include? ( options [ :subcommand ] ) task_options , remaining = remaining . partition { | s | s =~ / .+= / } if options [ :task_options ] unless task_options . empty? raise Bolt :: CLIError , "Parameters must be specified through either the --params " "option or param=value pairs, not both" end options [ :params_parsed ] = true elsif task_options . any? options [ :params_parsed ] = false options [ :task_options ] = Hash [ task_options . map { | a | a . split ( '=' , 2 ) } ] else options [ :params_parsed ] = true options [ :task_options ] = { } end end options [ :leftovers ] = remaining unless options . key? ( :verbose ) options [ :verbose ] = options [ :subcommand ] != 'plan' end validate ( options ) @parser_deprecations = parser . deprecations rescue Bolt :: Error => e fatal_error ( e ) raise e end
Parses the command and validates options.
Parses the command and validates options .
# This part aims to handle both `bolt <mode> --help` and `bolt help <mode>`. # Update the parser for the subcommand (or lack thereof) # Only parse task_options for task or plan # Default to verbose for everything except plans # Deprecation warnings can't be issued until after config is loaded, so # store them for later.