lib/bolt/bolt_option_parser.rb in bolt-1.37.0 vs lib/bolt/bolt_option_parser.rb in bolt-1.38.0

- old
+ new

@@ -5,12 +5,12 @@ require 'optparse' module Bolt class BoltOptionParser < OptionParser OPTIONS = { inventory: %w[nodes targets query rerun description], - authentication: %w[user password private-key host-key-check ssl ssl-verify], - escalation: %w[run-as sudo-password], + authentication: %w[user password password-prompt private-key host-key-check ssl ssl-verify], + escalation: %w[run-as sudo-password sudo-password-prompt], run_context: %w[concurrency inventoryfile save-rerun], global_config_setters: %w[modulepath boltdir configfile], transports: %w[transport connect-timeout tty], display: %w[format color verbose trace], global: %w[help version debug] }.freeze @@ -52,10 +52,13 @@ when 'project' case action when 'init' { flags: OPTIONS[:global], banner: PROJECT_INIT_HELP } + when 'migrate' + { flags: OPTIONS[:global] + %w[inventoryfile boltdir configfile], + banner: PROJECT_MIGRATE_HELP } else { flags: OPTIONS[:global], banner: PROJECT_HELP } end when 'puppetfile' @@ -129,10 +132,11 @@ bolt secret encrypt <plaintext> Encrypt a value bolt secret decrypt <encrypted> Decrypt a value bolt inventory show Show the list of targets an action would run on bolt group show Show the list of groups in the inventory bolt project init Create a new Bolt project + bolt project migrate Migrate a Bolt project to the latest version Run `bolt <subcommand> --help` to view specific examples. Available options are: HELP @@ -323,10 +327,11 @@ PROJECT_HELP = <<~PROJECT_HELP Usage: bolt project <action> Available actions are: init Create a new Bolt project + migrate Migrate a Bolt project to the latest version Available options are: PROJECT_HELP PROJECT_INIT_HELP = <<~PROJECT_INIT_HELP @@ -336,14 +341,26 @@ Specify a directory to create the Bolt project in. Defaults to the current working directory. Available options are: PROJECT_INIT_HELP + PROJECT_MIGRATE_HELP = <<~PROJECT_MIGRATE_HELP + Usage: bolt project migrate + + Migrate a Bolt project to the latest version. + Loads a Bolt project's inventory file and migrates it to the latest version. The + inventory file is modified in place and will not preserve comments or formatting. + + Available options are: + PROJECT_MIGRATE_HELP + + attr_reader :warnings def initialize(options) super() @options = options + @warnings = [] define('-n', '--nodes NODES', 'Alias for --targets', 'Deprecated in favor of --targets') do |nodes| @options [:nodes] ||= [] @@ -395,17 +412,25 @@ @options[:user] = user end define('-p', '--password [PASSWORD]', 'Password to authenticate with') do |password| if password.nil? + msg = "Optional parameter for --password is deprecated and will no longer prompt for password. " \ + "Use the prompt plugin or --password-prompt instead to prompt for passwords." + @warnings << { option: 'password', msg: msg } STDOUT.print "Please enter your password: " @options[:password] = STDIN.noecho(&:gets).chomp STDOUT.puts else @options[:password] = password end end + define('--password-prompt', 'Prompt for user to input password') do |_password| + STDERR.print "Please enter your password: " + @options[:password] = STDIN.noecho(&:gets).chomp + STDERR.puts + end define('--private-key KEY', 'Private ssh key to authenticate with') do |key| @options[:'private-key'] = key end define('--[no-]host-key-check', 'Check host keys with SSH') do |host_key_check| @options[:'host-key-check'] = host_key_check @@ -422,15 +447,23 @@ @options[:'run-as'] = user end define('--sudo-password [PASSWORD]', 'Password for privilege escalation') do |password| if password.nil? + msg = "Optional parameter for --sudo-password is deprecated and will no longer prompt for password. " \ + "Use the prompt plugin or --sudo-password-prompt instead to prompt for passwords." + @warnings << { option: 'sudo-password', msg: msg } STDOUT.print "Please enter your privilege escalation password: " @options[:'sudo-password'] = STDIN.noecho(&:gets).chomp STDOUT.puts else @options[:'sudo-password'] = password end + end + define('--sudo-password-prompt', 'Prompt for user to input escalation password') do |_password| + STDERR.print "Please enter your privilege escalation password: " + @options[:'sudo-password'] = STDIN.noecho(&:gets).chomp + STDERR.puts end separator "\nRun context:" define('-c', '--concurrency CONCURRENCY', Integer, 'Maximum number of simultaneous connections (default: 100)') do |concurrency|