Class: Bolt::BoltOptionParser

Inherits:
OptionParser
  • Object
show all
Defined in:
lib/bolt/bolt_option_parser.rb

Constant Summary collapse

PROJECT_PATHS =
%w[project].freeze
OPTIONS =
{ inventory: %w[targets query rerun],
authentication: %w[user password password-prompt private-key host-key-check ssl ssl-verify],
escalation: %w[run-as sudo-password sudo-password-prompt sudo-executable],
run_context: %w[concurrency inventoryfile save-rerun cleanup puppetdb],
global_config_setters: PROJECT_PATHS + %w[modulepath],
transports: %w[transport connect-timeout tty native-ssh ssh-command copy-command],
display: %w[format color verbose trace stream],
global: %w[help version log-level clear-cache] }.freeze
ACTION_OPTS =
OPTIONS.values.flatten.freeze
COLORS =
{
  cyan: "36"
}.freeze
"\#{colorize(:cyan, 'Name')}\n    bolt\n\n\#{colorize(:cyan, 'Usage')}\n    bolt <subcommand> [action] [options]\n\n\#{colorize(:cyan, 'Description')}\n    Bolt is an orchestration tool that automates the manual work it takes to\n    maintain your infrastructure.\n\n\#{colorize(:cyan, 'Subcommands')}\n    apply             Apply Puppet manifest code\n    command           Run a command remotely\n    file              Copy files between the controller and targets\n    group             Show the list of groups in the inventory\n    guide             View guides for Bolt concepts and features\n    inventory         Show the list of targets an action would run on\n    module            Manage Bolt project modules\n    lookup            Look up a value with Hiera\n    plan              Convert, create, show, and run Bolt plans\n    plugin            Show available plugins\n    policy            Apply, create, and show policies\n    project           Create and migrate Bolt projects\n    script            Upload a local script and run it remotely\n    secret            Create encryption keys and encrypt and decrypt values\n    task              Show and run Bolt tasks\n\n\#{colorize(:cyan, 'Guides')}\n    For a list of guides on Bolt's concepts and features, run 'bolt guide'.\n    Find Bolt's documentation at https://bolt.guide.\n"
APPLY_HELP =
"\#{colorize(:cyan, 'Name')}\n    apply\n\n\#{colorize(:cyan, 'Usage')}\n    bolt apply [manifest] {--targets TARGETS | --query QUERY | --rerun FILTER}\n      [options]\n\n\#{colorize(:cyan, 'Description')}\n    Apply Puppet manifest code on the specified targets.\n\n\#{colorize(:cyan, 'Documentation')}\n    For documentation see http://pup.pt/bolt-apply.\n\n\#{colorize(:cyan, 'Examples')}\n    bolt apply manifest.pp -t target\n    bolt apply -e \"file { '/etc/puppetlabs': ensure => present }\" -t target\n"
COMMAND_HELP =
"\#{colorize(:cyan, 'Name')}\n    command\n\n\#{colorize(:cyan, 'Usage')}\n    bolt command <action> [options]\n\n\#{colorize(:cyan, 'Description')}\n    Run a command on the specified targets.\n\n\#{colorize(:cyan, 'Documentation')}\n    For documentation see http://pup.pt/bolt-commands.\n\n\#{colorize(:cyan, 'Actions')}\n    run         Run a command on the specified targets.\n"
COMMAND_RUN_HELP =
"\#{colorize(:cyan, 'Name')}\n    command run\n\n\#{colorize(:cyan, 'Usage')}\n    bolt command run <command> {--targets TARGETS | --query QUERY | --rerun FILTER}\n      [options]\n\n\#{colorize(:cyan, 'Description')}\n    Run a command on the specified targets.\n\n\#{colorize(:cyan, 'Documentation')}\n    For documentation see http://pup.pt/bolt-commands.\n\n\#{colorize(:cyan, 'Examples')}\n    bolt command run 'uptime' -t target1,target2\n"
FILE_HELP =
"\#{colorize(:cyan, 'Name')}\n    file\n\n\#{colorize(:cyan, 'Usage')}\n    bolt file <action> [options]\n\n\#{colorize(:cyan, 'Description')}\n    Copy files and directories between the controller and targets.\n\n\#{colorize(:cyan, 'Documentation')}\n    For documentation see http://pup.pt/bolt-commands.\n\n\#{colorize(:cyan, 'Actions')}\n    download      Download a file or directory to the controller\n    upload        Upload a local file or directory from the controller\n"
FILE_DOWNLOAD_HELP =
"\#{colorize(:cyan, 'Name')}\n    file download\n\n\#{colorize(:cyan, 'Usage')}\n    bolt file download <source> <destination> {--targets TARGETS | --query QUERY | --rerun FILTER}\n      [options]\n\n\#{colorize(:cyan, 'Description')}\n    Download a file or directory from one or more targets.\n\n    Downloaded files and directories are saved to the a subdirectory\n    matching the target's name under the destination directory. The\n    destination directory is expanded relative to the downloads\n    subdirectory of the project directory.\n\n\#{colorize(:cyan, 'Documentation')}\n    For documentation see http://pup.pt/bolt-commands.\n\n\#{colorize(:cyan, 'Examples')}\n    bolt file download /etc/ssh_config ssh_config -t all\n"
FILE_UPLOAD_HELP =
"\#{colorize(:cyan, 'Name')}\n    file upload\n\n\#{colorize(:cyan, 'Usage')}\n    bolt file upload <source> <destination> {--targets TARGETS | --query QUERY | --rerun FILTER}\n      [options]\n\n\#{colorize(:cyan, 'Description')}\n    Upload a local file or directory.\n\n\#{colorize(:cyan, 'Documentation')}\n    For documentation see http://pup.pt/bolt-commands.\n\n\#{colorize(:cyan, 'Examples')}\n    bolt file upload /tmp/source /etc/profile.d/login.sh -t target1\n"
GROUP_HELP =
"\#{colorize(:cyan, 'Name')}\n    group\n\n\#{colorize(:cyan, 'Usage')}\n    bolt group <action> [options]\n\n\#{colorize(:cyan, 'Description')}\n    Show the list of groups in the inventory.\n\n\#{colorize(:cyan, 'Documentation')}\n    To learn more about the inventory run 'bolt guide inventory'.\n\n\#{colorize(:cyan, 'Actions')}\n    show          Show the list of groups in the inventory\n"
GROUP_SHOW_HELP =
"\#{colorize(:cyan, 'Name')}\n    group show\n\n\#{colorize(:cyan, 'Usage')}\n    bolt group show [options]\n\n\#{colorize(:cyan, 'Description')}\n    Show the list of groups in the inventory.\n\n\#{colorize(:cyan, 'Documentation')}\n    To learn more about the inventory run 'bolt guide inventory'.\n"
GUIDE_HELP =
"\#{colorize(:cyan, 'Name')}\n    guide\n\n\#{colorize(:cyan, 'Usage')}\n    bolt guide [topic] [options]\n\n\#{colorize(:cyan, 'Description')}\n    View guides for Bolt's concepts and features.\n\n    Omitting a topic will display a list of available guides,\n    while providing a topic will display the relevant guide.\n\n\#{colorize(:cyan, 'Examples')}\n    View a list of available guides\n      bolt guide\n    View the 'project' guide page\n      bolt guide project\n"
INVENTORY_HELP =
"\#{colorize(:cyan, 'Name')}\n    inventory\n\n\#{colorize(:cyan, 'Usage')}\n    bolt inventory <action> [options]\n\n\#{colorize(:cyan, 'Description')}\n    Show the list of targets an action would run on.\n\n\#{colorize(:cyan, 'Documentation')}\n    To learn more about the inventory run 'bolt guide inventory'.\n\n\#{colorize(:cyan, 'Actions')}\n    show          Show the list of targets an action would run on\n"
INVENTORY_SHOW_HELP =
"\#{colorize(:cyan, 'Name')}\n    inventory show\n\n\#{colorize(:cyan, 'Usage')}\n    bolt inventory show [options]\n\n\#{colorize(:cyan, 'Description')}\n    Show the list of targets an action would run on. This command will list\n    all targets in the project's inventory by default.\n\n    To filter the targets in the list, use the --targets, --query, or --rerun\n    options. To view detailed configuration and data for targets, use the\n    --detail option. To learn more about the inventory run 'bolt guide inventory'.\n\n\#{colorize(:cyan, 'Documentation')}\n    To learn more about the inventory run 'bolt guide inventory'.\n"
LOOKUP_HELP =
"\#{colorize(:cyan, 'Name')}\n    lookup\n\n\#{colorize(:cyan, 'Usage')}\n    bolt lookup <key> {--targets TARGETS | --query QUERY | --rerun FILTER | --plan-hierarchy}\n      [options]\n\n\#{colorize(:cyan, 'Description')}\n    Look up a value with Hiera.\n\n\#{colorize(:cyan, 'Documentation')}\n    Learn more about using Hiera with Bolt at https://pup.pt/bolt-hiera.\n\n\#{colorize(:cyan, 'Examples')}\n    bolt lookup password --targets servers\n    bolt lookup password --plan-hierarchy variable=value\n"
MODULE_HELP =
"\#{colorize(:cyan, 'Name')}\n    module\n  \n\#{colorize(:cyan, 'Usage')}\n    bolt module <action> [options]\n\n\#{colorize(:cyan, 'Description')}\n    Manage Bolt project modules.\n\n\#{colorize(:cyan, 'Documentation')}\n    To learn more about Bolt modules run 'bolt guide module'.\n\n\#{colorize(:cyan, 'Actions')}\n    add                   Add a module to the project\n    generate-types        Generate type references to register in plans\n    install               Install the project's modules\n    show                  List modules available to the Bolt project\n"
MODULE_ADD_HELP =
"\#{colorize(:cyan, 'Name')}\n    module add\n  \n\#{colorize(:cyan, 'Usage')}\n    bolt module add <module> [options]\n\n\#{colorize(:cyan, 'Description')}\n    Add a module to the project.\n\n    Module declarations are loaded from the project's configuration\n    file. Bolt will automatically resolve all module dependencies,\n    generate a Puppetfile, and install the modules.\n\n\#{colorize(:cyan, 'Documentation')}\n    To learn more about Bolt modules, run 'bolt guide module'.\n"
MODULE_GENERATETYPES_HELP =
"\#{colorize(:cyan, 'Name')}\n    module generate-types\n\n\#{colorize(:cyan, 'Usage')}\n    bolt module generate-types [options]\n\n\#{colorize(:cyan, 'Description')}\n    Generate type references to register in plans. To learn more about\n    Bolt modules, run 'bolt guide module'.\n\n\#{colorize(:cyan, 'Documentation')}\n    To learn more about Bolt modules, run 'bolt guide module'.\n"
MODULE_INSTALL_HELP =
"\#{colorize(:cyan, 'Name')}\n    module install\n  \n\#{colorize(:cyan, 'Usage')}\n    bolt module install [options]\n\n\#{colorize(:cyan, 'Description')}\n    Install the project's modules.\n\n    Module declarations are loaded from the project's configuration\n    file. Bolt will automatically resolve all module dependencies,\n    generate a Puppetfile, and install the modules.\n\n\#{colorize(:cyan, 'Documentation')}\n    To learn more about Bolt modules, run 'bolt guide module'.\n"
MODULE_SHOW_HELP =
"\#{colorize(:cyan, 'Name')}\n    module show\n\n\#{colorize(:cyan, 'Usage')}\n    bolt module show [module name] [options]\n\n\#{colorize(:cyan, 'Description')}\n    List modules available to the Bolt project.\n\n    Providing the name of a module will display detailed documentation for\n    the module.\n\n\#{colorize(:cyan, 'Documentation')}\n    To learn more about Bolt modules, run 'bolt guide module'.\n"
PLAN_HELP =
"\#{colorize(:cyan, 'Name')}\n    plan\n\n\#{colorize(:cyan, 'Usage')}\n    bolt plan <action> [options]\n\n\#{colorize(:cyan, 'Description')}\n    Convert, create, show, and run Bolt plans.\n\n\#{colorize(:cyan, 'Documentation')}\n    Learn more about Bolt plans at https://pup.pt/bolt-plans.\n\n\#{colorize(:cyan, 'Actions')}\n    convert       Convert a YAML plan to a Bolt plan\n    new           Create a new plan in the current project\n    run           Run a plan on the specified targets\n    show          Show available plans and plan documentation\n"
PLAN_CONVERT_HELP =
"\#{colorize(:cyan, 'Name')}\n    plan convert\n\n\#{colorize(:cyan, 'Usage')}\n    bolt plan convert <plan name> [options]\n\n\#{colorize(:cyan, 'Description')}\n    Convert a YAML plan to a Puppet language plan and print the converted\n    plan to stdout.\n\n    Converting a YAML plan might result in a plan that is syntactically\n    correct but has different behavior. Always verify a converted plan's\n    functionality. Note that the converted plan is not written to a file.\n\n\#{colorize(:cyan, 'Documentation')}\n    Learn more about Bolt plans at https://pup.pt/bolt-plans.\n\n\#{colorize(:cyan, 'Examples')}\n    bolt plan convert myproject::myplan\n    bolt plan convert path/to/plan/myplan.yaml\n"
PLAN_NEW_HELP =
"\#{colorize(:cyan, 'Name')}\n    plan new\n  \n\#{colorize(:cyan, 'Usage')}\n    bolt plan new <plan name> [options]\n  \n\#{colorize(:cyan, 'Description')}\n    Create a new plan in the current project.\n\n\#{colorize(:cyan, 'Documentation')}\n    Learn more about Bolt plans at https://pup.pt/bolt-plans.\n\n\#{colorize(:cyan, 'Examples')}\n    bolt plan new myproject::myplan\n"
PLAN_RUN_HELP =
"\#{colorize(:cyan, 'Name')}\n    plan run\n\n\#{colorize(:cyan, 'Usage')}\n    bolt plan run <plan name> [parameters] [options]\n\n\#{colorize(:cyan, 'Description')}\n    Run a plan on the specified targets.\n\n\#{colorize(:cyan, 'Documentation')}\n    Learn more about Bolt plans at https://pup.pt/bolt-plans.\n\n\#{colorize(:cyan, 'Examples')}\n    bolt plan run canary --targets target1,target2 command=hostname\n"
PLAN_SHOW_HELP =
"\#{colorize(:cyan, 'Name')}\n    plan show\n\n\#{colorize(:cyan, 'Usage')}\n    bolt plan show [plan name] [options]\n\n\#{colorize(:cyan, 'Description')}\n    Show available plans and plan documentation.\n\n    Omitting the name of a plan will display a list of plans available\n    in the Bolt project.\n\n    Providing the name of a plan will display detailed documentation for\n    the plan, including a list of available parameters.\n\n\#{colorize(:cyan, 'Documentation')}\n    Learn more about Bolt plans at https://pup.pt/bolt-plans.\n\n\#{colorize(:cyan, 'Examples')}\n    Display a list of available plans\n      bolt plan show\n    Display documentation for the aggregate::count plan\n      bolt plan show aggregate::count\n"
PLUGIN_HELP =
"\#{colorize(:cyan, 'Name')}\n    plugin\n\n\#{colorize(:cyan, 'Usage')}\n    bolt plugin <action> [options]\n\n\#{colorize(:cyan, 'Description')}\n    Show available plugins.\n\n\#{colorize(:cyan, 'Documentation')}\n    Learn more about Bolt plugins at https://pup.pt/bolt-plugins.\n\n\#{colorize(:cyan, 'Actions')}\n    show          Show available plugins\n"
PLUGIN_SHOW_HELP =
"\#{colorize(:cyan, 'Name')}\n    plugin show\n\n\#{colorize(:cyan, 'Usage')}\n    bolt plugin show [options]\n\n\#{colorize(:cyan, 'Description')}\n    Show available plugins.\n\n\#{colorize(:cyan, 'Documentation')}\n    Learn more about Bolt plugins at https://pup.pt/bolt-plugins.\n"
POLICY_HELP =
"\#{colorize(:cyan, 'Name')}\n    policy\n\n\#{colorize(:cyan, 'Usage')}\n    bolt policy <action> [options]\n\n\#{colorize(:cyan, 'Description')}\n    Apply, create, and show policies.\n\n\#{colorize(:cyan, 'Actions')}\n    apply         Apply a policy to the specified targets\n    new           Create a new policy in the current project\n    show          Show available policy\n"
POLICY_APPLY_HELP =
"\#{colorize(:cyan, 'Name')}\n    policy apply\n\n\#{colorize(:cyan, 'Usage')}\n    bolt policy apply <policy> [options]\n\n\#{colorize(:cyan, 'Description')}\n    Apply a policy to the specified targets.\n"
POLICY_NEW_HELP =
"\#{colorize(:cyan, 'Name')}\n    policy new\n\n\#{colorize(:cyan, 'Usage')}\n    bolt policy new <policy> [options]\n\n\#{colorize(:cyan, 'Description')}\n    Create a new policy in the current project.\n"
POLICY_SHOW_HELP =
"\#{colorize(:cyan, 'Name')}\n    policy show\n\n\#{colorize(:cyan, 'Usage')}\n    bolt policy show [options]\n\n\#{colorize(:cyan, 'Description')}\n    Show available policies.\n"
PROJECT_HELP =
"\#{colorize(:cyan, 'Name')}\n    project\n\n\#{colorize(:cyan, 'Usage')}\n    bolt project <action> [options]\n\n\#{colorize(:cyan, 'Description')}\n    Create and migrate Bolt projects\n\n\#{colorize(:cyan, 'Documentation')}\n    To learn more about Bolt projects, run 'bolt guide project'.\n\n\#{colorize(:cyan, 'Actions')}\n    init              Create a new Bolt project\n    migrate           Migrate a Bolt project to the latest version\n"
PROJECT_INIT_HELP =
"\#{colorize(:cyan, 'Name')}\n    project init\n\n\#{colorize(:cyan, 'Usage')}\n    bolt project init [name] [options]\n\n\#{colorize(:cyan, 'Description')}\n    Create a new Bolt project in the current working directory.\n\n    Specify a name for the Bolt project. Defaults to the basename of the current working directory.\n\n\#{colorize(:cyan, 'Documentation')}\n    To learn more about Bolt projects, run 'bolt guide project'.\n\n\#{colorize(:cyan, 'Examples')}\n    Create a new Bolt project using the directory as the project name.\n      bolt project init\n    Create a new Bolt project with a specified name.\n      bolt project init myproject\n    Create a new Bolt project with existing modules.\n      bolt project init --modules puppetlabs-apt,puppetlabs-ntp\n"
PROJECT_MIGRATE_HELP =
"\#{colorize(:cyan, 'Name')}\n    project migrate\n\n\#{colorize(:cyan, 'Usage')}\n    bolt project migrate [options]\n\n\#{colorize(:cyan, 'Description')}\n    Migrate a Bolt project to use current best practices and the latest version of\n    configuration files.\n\n\#{colorize(:cyan, 'Documentation')}\n    To learn more about Bolt projects, run 'bolt guide project'.\n"
SCRIPT_HELP =
"\#{colorize(:cyan, 'Name')}\n    script\n\n\#{colorize(:cyan, 'Usage')}\n    bolt script <action> [options]\n\n\#{colorize(:cyan, 'Description')}\n    Run a script on the specified targets.\n\n\#{colorize(:cyan, 'Documentation')}\n    Learn more about running scripts at https://pup.pt/bolt-commands.\n\n\#{colorize(:cyan, 'Actions')}\n    run         Run a script on the specified targets.\n"
SCRIPT_RUN_HELP =
"\#{colorize(:cyan, 'Name')}\n    script run\n\n\#{colorize(:cyan, 'Usage')}\n    bolt script run <script> [arguments] {--targets TARGETS | --query QUERY | --rerun FILTER}\n      [options]\n\n\#{colorize(:cyan, 'Description')}\n    Run a script on the specified targets.\n\n    Arguments passed to a script are passed literally and are not interpolated\n    by the shell. Any arguments containing spaces or special characters should\n    be quoted.\n\n\#{colorize(:cyan, 'Documentation')}\n    Learn more about running scripts at https://pup.pt/bolt-commands.\n\n\#{colorize(:cyan, 'Examples')}\n    bolt script run myscript.sh 'echo hello' --targets target1,target2\n"
SECRET_HELP =
"\#{colorize(:cyan, 'Name')}\n    secret\n\n\#{colorize(:cyan, 'Usage')}\n    bolt secret <action> [options]\n\n\#{colorize(:cyan, 'Description')}\n    Create encryption keys and encrypt and decrypt values.\n\n\#{colorize(:cyan, 'Documentation')}\n    Learn more about secrets plugins at http://pup.pt/bolt-plugins.\n\n\#{colorize(:cyan, 'Actions')}\n    createkeys           Create new encryption keys\n    encrypt              Encrypt a value\n    decrypt              Decrypt a value\n"
SECRET_CREATEKEYS_HELP =
"\#{colorize(:cyan, 'Name')}\n    secret createkeys\n\n\#{colorize(:cyan, 'Usage')}\n    bolt secret createkeys [options]\n\n\#{colorize(:cyan, 'Description')}\n    Create new encryption keys.\n\n\#{colorize(:cyan, 'Documentation')}\n    Learn more about secrets plugins at http://pup.pt/bolt-plugins.\n"
SECRET_DECRYPT_HELP =
"\#{colorize(:cyan, 'Name')}\n    secret decrypt\n\n\#{colorize(:cyan, 'Usage')}\n    bolt secret decrypt <ciphertext> [options]\n\n\#{colorize(:cyan, 'Description')}\n    Decrypt a value.\n\n\#{colorize(:cyan, 'Documentation')}\n    Learn more about secrets plugins at http://pup.pt/bolt-plugins.\n"
SECRET_ENCRYPT_HELP =
"\#{colorize(:cyan, 'Name')}\n    secret encrypt\n\n\#{colorize(:cyan, 'Usage')}\n  bolt secret encrypt <plaintext> [options]\n\n\#{colorize(:cyan, 'Description')}\n    Encrypt a value.\n\n\#{colorize(:cyan, 'Documentation')}\n    Learn more about secrets plugins at http://pup.pt/bolt-plugins.\n"
TASK_HELP =
"\#{colorize(:cyan, 'Name')}\n    task\n\n\#{colorize(:cyan, 'Usage')}\n    bolt task <action> [options]\n\n\#{colorize(:cyan, 'Description')}\n    Show and run Bolt tasks.\n\n\#{colorize(:cyan, 'Documentation')}\n    Learn more about Bolt tasks at http://pup.pt/bolt-tasks.\n\n\#{colorize(:cyan, 'Actions')}\n    run          Run a Bolt task\n    show         Show available tasks and task documentation\n"
TASK_RUN_HELP =
"\#{colorize(:cyan, 'Name')}\n    task run\n\n\#{colorize(:cyan, 'Usage')}\n    bolt task run <task name> [parameters] {--targets TARGETS | --query QUERY | --rerun FILTER}\n      [options]\n\n\#{colorize(:cyan, 'Description')}\n    Run a task on the specified targets.\n\n    Parameters take the form parameter=value.\n\n\#{colorize(:cyan, 'Documentation')}\n    Learn more about Bolt tasks at http://pup.pt/bolt-tasks.\n\n\#{colorize(:cyan, 'Examples')}\n    bolt task run package --targets target1,target2 action=status name=bash\n"
TASK_SHOW_HELP =
"\#{colorize(:cyan, 'Name')}\n    task show\n\n\#{colorize(:cyan, 'Usage')}\n    bolt task show [task name] [options]\n\n\#{colorize(:cyan, 'Description')}\n    Show available tasks and task documentation.\n\n    Omitting the name of a task will display a list of tasks available\n    in the Bolt project.\n\n    Providing the name of a task will display detailed documentation for\n    the task, including a list of available parameters.\n\n\#{colorize(:cyan, 'Documentation')}\n    Learn more about Bolt tasks at http://pup.pt/bolt-tasks.\n\n\#{colorize(:cyan, 'Examples')}\n    Display a list of available tasks\n      bolt task show\n    Display documentation for the canary task\n      bolt task show canary\n"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BoltOptionParser



942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
# File 'lib/bolt/bolt_option_parser.rb', line 942

def initialize(options)
  super()

  @options = options

  separator "\n#{self.class.colorize(:cyan, 'Inventory options')}"
  define('-t', '--targets TARGETS', 'Identifies the targets of the command.',
         "For more information, see 'bolt guide targets'.") do |targets|
    @options[:targets] ||= []
    @options[:targets] << Bolt::Util.get_arg_input(targets)
  end
  define('-q', '--query QUERY', 'Query PuppetDB to determine the targets.') do |query|
    @options[:query] = query
  end
  define("--rerun FILTER", "Retry on targets from the last run.",
         "Available filters are 'all', 'failure', and 'success'.") do |rerun|
    @options[:rerun] = rerun
  end
  define('--noop', 'See what changes Bolt will make without actually executing the changes.') do |_|
    @options[:noop] = true
  end
  define('--params PARAMETERS',
         "Parameters to a task or plan as json, a json file '@<file>', or on stdin '-'.") do |params|
    @options[:params] = parse_params(params)
  end
  define('-e', '--execute CODE',
         "Puppet manifest code to apply to the targets.") do |code|
    @options[:code] = code
  end
  define('--detail', 'Show resolved configuration for the targets.') do |detail|
    @options[:detail] = detail
  end

  separator "\n#{self.class.colorize(:cyan, 'Authentication options')}"
  define('-u', '--user USER', 'User to authenticate as.') do |user|
    @options[:user] = user
  end
  define('-p', '--password PASSWORD',
         'Password to authenticate with.') do |password|
    @options[:password] = password
  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', 'Path to private ssh key to authenticate with.') do |key|
    @options[:'private-key'] = File.expand_path(key)
  end
  define('--[no-]host-key-check', 'Check host keys with SSH.') do |host_key_check|
    @options[:'host-key-check'] = host_key_check
  end
  define('--[no-]ssl', 'Use SSL with WinRM.') do |ssl|
    @options[:ssl] = ssl
  end
  define('--[no-]ssl-verify', 'Verify remote host SSL certificate with WinRM.') do |ssl_verify|
    @options[:'ssl-verify'] = ssl_verify
  end

  separator "\n#{self.class.colorize(:cyan, 'Escalation options')}"
  define('--run-as USER', 'User to run as using privilege escalation.') do |user|
    @options[:'run-as'] = user
  end
  define('--sudo-password PASSWORD',
         'Password for privilege escalation.') do |password|
    @options[:'sudo-password'] = password
  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
  define('--sudo-executable EXEC', "Experimental. Specify an executable for running as another user.") do |exec|
    @options[:'sudo-executable'] = exec
  end

  separator "\n#{self.class.colorize(:cyan, 'Run context options')}"
  define('-c', '--concurrency CONCURRENCY', Integer,
         'Maximum number of simultaneous connections.') do |concurrency|
    @options[:concurrency] = concurrency
  end
  define('--compile-concurrency CONCURRENCY', Integer,
         'Maximum number of simultaneous manifest block compiles (default: number of cores).') do |concurrency|
    @options[:'compile-concurrency'] = concurrency
  end
  define('--[no-]cleanup',
         'Whether to clean up temporary files created on targets.') do |cleanup|
    @options[:cleanup] = cleanup
  end
  define('-m', '--modulepath MODULES',
         "List of directories containing modules, separated by '#{File::PATH_SEPARATOR}'",
         'Directories are case-sensitive.') do |modulepath|
    # When specified from the CLI, modulepath entries are relative to pwd
    @options[:modulepath] = modulepath.split(File::PATH_SEPARATOR).map do |moduledir|
      File.expand_path(moduledir)
    end
  end
  define('--project PATH',
         'Path to load the Bolt project from (default: autodiscovered from current dir).') do |path|
    @options[:project] = path
  end
  define('--hiera-config PATH',
         'Specify where to load Hiera config from (default: <project>/hiera.yaml).') do |path|
    @options[:'hiera-config'] = File.expand_path(path)
  end
  define('-i', '--inventoryfile PATH',
         'Specify where to load inventory from (default: <project>/inventory.yaml).') do |path|
    if ENV.include?(Bolt::Inventory::ENVIRONMENT_VAR)
      raise Bolt::CLIError, "Cannot pass inventory file when #{Bolt::Inventory::ENVIRONMENT_VAR} is set"
    end
    @options[:inventoryfile] = File.expand_path(path)
  end
  define('--[no-]save-rerun', 'Whether to update the rerun file after this command.') do |save|
    @options[:'save-rerun'] = save
  end
  define('--puppetdb INSTANCE', 'The named PuppetDB instance to connect to by default.') do |instance|
    @options[:default_puppetdb] = instance
  end

  separator "\n#{self.class.colorize(:cyan, 'Remote environment options')}"
  define('--env-var ENVIRONMENT_VARIABLES', 'Environment variables to set on the target.') do |envvar|
    unless envvar.include?('=')
      raise Bolt::CLIError, "Environment variables must be specified using 'myenvvar=key' format"
    end
    @options[:env_vars] ||= {}
    @options[:env_vars].store(*envvar.split('=', 2))
  end

  separator "\n#{self.class.colorize(:cyan, 'Transport options')}"
  define('--transport TRANSPORT', TRANSPORTS.keys.map(&:to_s),
         "Specify a default transport: #{TRANSPORTS.keys.join(', ')}.",
         "For more information, see 'bolt guide transports'.") do |t|
    @options[:transport] = t
  end
  define('--[no-]native-ssh',
         'Experimental. Whether to shell out to native SSH or use the net-ssh Ruby library.') do |bool|
    @options[:'native-ssh'] = bool
  end
  define('--ssh-command EXEC', "Experimental. Executable to use instead of the net-ssh Ruby library.") do |exec|
    @options[:'ssh-command'] = exec
  end
  define('--copy-command EXEC',
         "Experimental. Command to copy files to remote hosts if using native SSH.") do |exec|
    @options[:'copy-command'] = exec
  end
  define('--connect-timeout TIMEOUT', Integer, 'Connection timeout in seconds (defaults vary).') do |timeout|
    @options[:'connect-timeout'] = timeout
  end
  define('--[no-]tty', 'Request a pseudo TTY on targets that support it.') do |tty|
    @options[:tty] = tty
  end
  define('--tmpdir DIR', 'The directory to upload and execute temporary files on the target.') do |tmpdir|
    @options[:tmpdir] = tmpdir
  end

  separator "\n#{self.class.colorize(:cyan, 'Module options')}"
  define('--[no-]resolve',
         'Use --no-resolve to install modules listed in the Puppetfile without resolving modules configured',
         'in Bolt project configuration.') do |resolve|
    @options[:resolve] = resolve
  end

  separator "\n#{self.class.colorize(:cyan, 'Lookup options')}"
  define('--plan-hierarchy', 'Look up a value with Hiera in the context of a specific plan.') do |_|
    @options[:plan_hierarchy] = true
  end

  separator "\n#{self.class.colorize(:cyan, 'Plan options')}"
  define('--pp', 'Create a new Puppet language plan.') do |_|
    @options[:puppet] = true
  end
  define('--script SCRIPT', 'Create a new plan that wraps a script.') do |path|
    # If the path is a relative, absolute, or not a scripts path, raise an
    # error. This flag is intended to be used to create shareable plans.
    #
    # This also limits valid mounts to files and scripts, which we may want
    # to expand in the future.
    if File.exist?(path) || Pathname.new(path).absolute? ||
       !%w[scripts files].include?(path.split(File::SEPARATOR)[1])
      raise Bolt::CLIError, "The script must be a detailed Puppet file reference, " \
        "for example 'mymodule/scripts/myscript.sh'. See http://pup.pt/bolt-scripts for " \
        "more information on detailed Puppet file references."
    end

    @options[:plan_script] = path
  end

  separator "\n#{self.class.colorize(:cyan, 'Display options')}"
  define('--filter FILTER', 'Filter tasks and plans by a matching substring.') do |filter|
    unless /^[a-z0-9_:]+$/.match(filter)
      msg = "Illegal characters in filter string '#{filter}'. Filters can "\
      "only include lowercase letters, numbers, underscores, and colons."
      raise Bolt::CLIError, msg
    end
    @options[:filter] = filter
  end
  define('--format FORMAT', 'Output format to use: human, json, or rainbow.') do |format|
    @options[:format] = format
  end
  define('--[no-]color', 'Whether to show output in color.') do |color|
    @options[:color] = color
  end
  define('-v', '--[no-]verbose', 'Display verbose logging.') do |value|
    @options[:verbose] = value
  end
  define('--stream',
         'Stream output from scripts and commands to the console.',
         'Run with --no-verbose to prevent Bolt from displaying output',
         'a second time after the action is completed.') do |_|
    @options[:stream] = true
  end
  define('--trace', 'Display error stack traces.') do |_|
    @options[:trace] = true
  end

  separator "\n#{self.class.colorize(:cyan, 'Additional options')}"
  define('--modules MODULES',
         'A comma-separated list of modules to install from the Puppet Forge',
         'when initializing a project. Resolves and installs all dependencies.') do |modules|
    @options[:modules] = modules.split(',').map { |mod| { 'name' => mod } }
  end
  define('--force', 'Force a destructive action.') do |_force|
    @options[:force] = true
  end

  separator "\n#{self.class.colorize(:cyan, 'Global options')}"
  define('-h', '--help', 'Display help.') do |_|
    @options[:help] = true
  end
  define('--version', 'Display the version.') do |_|
    @options[:version] = true
  end
  define('--log-level LEVEL',
         "Set the log level for the console. Available options are",
         "trace, debug, info, warn, error, fatal.") do |level|
    @options[:log] = { 'console' => { 'level' => level } }
  end
  define('--clear-cache',
         "Clear plugin, plan, and task caches before executing.") do |_|
    @options[:clear_cache] = true
  end
  define('--plugin PLUGIN', 'Select the plugin to use.') do |plug|
    @options[:plugin] = plug
  end
end

Class Method Details

.colorize(color, string) ⇒ Object



190
191
192
193
194
195
196
# File 'lib/bolt/bolt_option_parser.rb', line 190

def self.colorize(color, string)
  if $stdout.isatty
    "\033[#{COLORS[color]}m#{string}\033[0m"
  else
    string
  end
end

Instance Method Details

#get_help_text(subcommand, action = nil) ⇒ Object



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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/bolt/bolt_option_parser.rb', line 21

def get_help_text(subcommand, action = nil)
  case subcommand
  when 'apply'
    { flags: ACTION_OPTS + %w[noop execute compile-concurrency hiera-config],
      banner: APPLY_HELP }
  when 'command'
    case action
    when 'run'
      { flags: ACTION_OPTS + %w[env-var],
        banner: COMMAND_RUN_HELP }
    else
      { flags: OPTIONS[:global],
        banner: COMMAND_HELP }
    end
  when 'file'
    case action
    when 'upload'
      { flags: ACTION_OPTS + %w[tmpdir],
        banner: FILE_UPLOAD_HELP }
    when 'download'
      { flags: ACTION_OPTS,
        banner: FILE_DOWNLOAD_HELP }
    else
      { flags: OPTIONS[:global],
        banner: FILE_HELP }
    end
  when 'inventory'
    case action
    when 'show'
      { flags: OPTIONS[:inventory] + OPTIONS[:global] +
        PROJECT_PATHS + %w[format inventoryfile detail],
        banner: INVENTORY_SHOW_HELP }
    else
      { flags: OPTIONS[:global],
        banner: INVENTORY_HELP }
    end
  when 'group'
    case action
    when 'show'
      { flags: OPTIONS[:global] + PROJECT_PATHS + %w[format inventoryfile],
        banner: GROUP_SHOW_HELP }
    else
      { flags: OPTIONS[:global],
        banner: GROUP_HELP }
    end
  when 'guide'
    { flags: OPTIONS[:global] + %w[format],
      banner: GUIDE_HELP }
  when 'lookup'
    { flags: ACTION_OPTS + %w[hiera-config plan-hierarchy],
      banner: LOOKUP_HELP }
  when 'module'
    case action
    when 'add'
      { flags: OPTIONS[:global] + PROJECT_PATHS,
        banner: MODULE_ADD_HELP }
    when 'generate-types'
      { flags: OPTIONS[:global] + OPTIONS[:global_config_setters],
        banner: MODULE_GENERATETYPES_HELP }
    when 'install'
      { flags: OPTIONS[:global] + PROJECT_PATHS + %w[force resolve],
        banner: MODULE_INSTALL_HELP }
    when 'show'
      { flags: OPTIONS[:global] + OPTIONS[:global_config_setters],
        banner: MODULE_SHOW_HELP }
    else
      { flags: OPTIONS[:global],
        banner: MODULE_HELP }
    end
  when 'plan'
    case action
    when 'convert'
      { flags: OPTIONS[:global] + OPTIONS[:global_config_setters],
        banner: PLAN_CONVERT_HELP }
    when 'new'
      { flags: OPTIONS[:global] + PROJECT_PATHS + %w[pp],
        banner: PLAN_NEW_HELP }
    when 'run'
      { flags: ACTION_OPTS + %w[params compile-concurrency tmpdir hiera-config],
        banner: PLAN_RUN_HELP }
    when 'show'
      { flags: OPTIONS[:global] + OPTIONS[:global_config_setters] + %w[filter format],
        banner: PLAN_SHOW_HELP }
    else
      { flags: OPTIONS[:global],
        banner: PLAN_HELP }
    end
  when 'plugin'
    case action
    when 'show'
      { flags: OPTIONS[:global] + %w[color format modulepath project],
        banner: PLUGIN_SHOW_HELP }
    else
      { flags: OPTIONS[:global],
        banner: PLUGIN_HELP }
    end
  when 'policy'
    case action
    when 'apply'
      { flags: ACTION_OPTS + %w[compile-concurrency hiera-config noop],
        banner: POLICY_APPLY_HELP }
    when 'new'
      { flags: OPTIONS[:global] + PROJECT_PATHS,
        banner: POLICY_NEW_HELP }
    when 'show'
      { flags: OPTIONS[:global] + PROJECT_PATHS,
        banner: POLICY_SHOW_HELP }
    else
      { flags: OPTIONS[:global],
        banner: POLICY_HELP }
    end
  when 'project'
    case action
    when 'init'
      { flags: OPTIONS[:global] + %w[modules],
        banner: PROJECT_INIT_HELP }
    when 'migrate'
      { flags: OPTIONS[:global] + PROJECT_PATHS + %w[inventoryfile],
        banner: PROJECT_MIGRATE_HELP }
    else
      { flags: OPTIONS[:global],
        banner: PROJECT_HELP }
    end
  when 'script'
    case action
    when 'run'
      { flags: ACTION_OPTS + %w[tmpdir env-var],
        banner: SCRIPT_RUN_HELP }
    else
      { flags: OPTIONS[:global],
        banner: SCRIPT_HELP }
    end
  when 'secret'
    case action
    when 'createkeys'
      { flags: OPTIONS[:global] + OPTIONS[:global_config_setters] + %w[plugin force],
        banner: SECRET_CREATEKEYS_HELP }
    when 'decrypt'
      { flags: OPTIONS[:global] + OPTIONS[:global_config_setters] + %w[plugin],
        banner: SECRET_DECRYPT_HELP }
    when 'encrypt'
      { flags: OPTIONS[:global] + OPTIONS[:global_config_setters] + %w[plugin],
        banner: SECRET_ENCRYPT_HELP }
    else
      { flags: OPTIONS[:global],
        banner: SECRET_HELP }
    end
  when 'task'
    case action
    when 'run'
      { flags: ACTION_OPTS + %w[params tmpdir noop],
        banner: TASK_RUN_HELP }
    when 'show'
      { flags: OPTIONS[:global] + OPTIONS[:global_config_setters] + %w[filter format],
        banner: TASK_SHOW_HELP }
    else
      { flags: OPTIONS[:global],
        banner: TASK_HELP }
    end
  else
    { flags: OPTIONS[:global],
      banner: BANNER }
  end
end

#parse_params(params) ⇒ Object



1209
1210
1211
1212
1213
1214
# File 'lib/bolt/bolt_option_parser.rb', line 1209

def parse_params(params)
  json = Bolt::Util.get_arg_input(params)
  JSON.parse(json)
rescue JSON::ParserError => e
  raise Bolt::CLIError, "Unable to parse --params value as JSON: #{e}"
end

#permute(args) ⇒ Object



1216
1217
1218
1219
1220
1221
1222
1223
1224
# File 'lib/bolt/bolt_option_parser.rb', line 1216

def permute(args)
  super(args)
rescue OptionParser::MissingArgument => e
  raise Bolt::CLIError, "Option '#{e.args.first}' needs a parameter"
rescue OptionParser::InvalidArgument => e
  raise Bolt::CLIError, "Invalid parameter specified for option '#{e.args.first}': #{e.args[1]}"
rescue OptionParser::InvalidOption, OptionParser::AmbiguousOption => e
  raise Bolt::CLIError, "Unknown argument '#{e.args.first}'"
end

#remove_excluded_opts(option_list) ⇒ Object



1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
# File 'lib/bolt/bolt_option_parser.rb', line 1188

def remove_excluded_opts(option_list)
  # Remove any options that are not available for the specified subcommand
  top.list.delete_if do |opt|
    opt.respond_to?(:switch_name) && !option_list.include?(opt.switch_name)
  end
  # Remove any separators if all options of that type have been removed
  top.list.delete_if do |opt|
    i = top.list.index(opt)
    opt.is_a?(String) && top.list[i + 1].is_a?(String)
  end
end

#updateObject



1200
1201
1202
1203
1204
1205
1206
1207
# File 'lib/bolt/bolt_option_parser.rb', line 1200

def update
  help_text = get_help_text(@options[:subcommand], @options[:action])
  # Update the banner according to the subcommand
  self.banner = help_text[:banner]
  # Builds the option list for the specified subcommand and removes all excluded
  # options from the help text
  remove_excluded_opts(help_text[:flags])
end