/
bolt_option_parser.rb
1226 lines (1000 loc) · 41.5 KB
/
bolt_option_parser.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
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
# frozen_string_literal: true
# Note this file includes very few 'requires' because it expects to be used from the CLI.
require 'optparse'
module Bolt
class BoltOptionParser < OptionParser
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
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
COLORS = {
cyan: "36"
}.freeze
def self.colorize(color, string)
if $stdout.isatty
"\033[#{COLORS[color]}m#{string}\033[0m"
else
string
end
end
BANNER = <<~HELP
#{colorize(:cyan, 'Name')}
bolt
#{colorize(:cyan, 'Usage')}
bolt <subcommand> [action] [options]
#{colorize(:cyan, 'Description')}
Bolt is an orchestration tool that automates the manual work it takes to
maintain your infrastructure.
#{colorize(:cyan, 'Subcommands')}
apply Apply Puppet manifest code
command Run a command remotely
file Copy files between the controller and targets
group Show the list of groups in the inventory
guide View guides for Bolt concepts and features
inventory Show the list of targets an action would run on
module Manage Bolt project modules
lookup Look up a value with Hiera
plan Convert, create, show, and run Bolt plans
plugin Show available plugins
policy Apply, create, and show policies
project Create and migrate Bolt projects
script Upload a local script and run it remotely
secret Create encryption keys and encrypt and decrypt values
task Show and run Bolt tasks
#{colorize(:cyan, 'Guides')}
For a list of guides on Bolt's concepts and features, run 'bolt guide'.
Find Bolt's documentation at https://bolt.guide.
HELP
APPLY_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
apply
#{colorize(:cyan, 'Usage')}
bolt apply [manifest] {--targets TARGETS | --query QUERY | --rerun FILTER}
[options]
#{colorize(:cyan, 'Description')}
Apply Puppet manifest code on the specified targets.
#{colorize(:cyan, 'Documentation')}
For documentation see http://pup.pt/bolt-apply.
#{colorize(:cyan, 'Examples')}
bolt apply manifest.pp -t target
bolt apply -e "file { '/etc/puppetlabs': ensure => present }" -t target
HELP
COMMAND_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
command
#{colorize(:cyan, 'Usage')}
bolt command <action> [options]
#{colorize(:cyan, 'Description')}
Run a command on the specified targets.
#{colorize(:cyan, 'Documentation')}
For documentation see http://pup.pt/bolt-commands.
#{colorize(:cyan, 'Actions')}
run Run a command on the specified targets.
HELP
COMMAND_RUN_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
command run
#{colorize(:cyan, 'Usage')}
bolt command run <command> {--targets TARGETS | --query QUERY | --rerun FILTER}
[options]
#{colorize(:cyan, 'Description')}
Run a command on the specified targets.
#{colorize(:cyan, 'Documentation')}
For documentation see http://pup.pt/bolt-commands.
#{colorize(:cyan, 'Examples')}
bolt command run 'uptime' -t target1,target2
HELP
FILE_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
file
#{colorize(:cyan, 'Usage')}
bolt file <action> [options]
#{colorize(:cyan, 'Description')}
Copy files and directories between the controller and targets.
#{colorize(:cyan, 'Documentation')}
For documentation see http://pup.pt/bolt-commands.
#{colorize(:cyan, 'Actions')}
download Download a file or directory to the controller
upload Upload a local file or directory from the controller
HELP
FILE_DOWNLOAD_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
file download
#{colorize(:cyan, 'Usage')}
bolt file download <source> <destination> {--targets TARGETS | --query QUERY | --rerun FILTER}
[options]
#{colorize(:cyan, 'Description')}
Download a file or directory from one or more targets.
Downloaded files and directories are saved to the a subdirectory
matching the target's name under the destination directory. The
destination directory is expanded relative to the downloads
subdirectory of the project directory.
#{colorize(:cyan, 'Documentation')}
For documentation see http://pup.pt/bolt-commands.
#{colorize(:cyan, 'Examples')}
bolt file download /etc/ssh_config ssh_config -t all
HELP
FILE_UPLOAD_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
file upload
#{colorize(:cyan, 'Usage')}
bolt file upload <source> <destination> {--targets TARGETS | --query QUERY | --rerun FILTER}
[options]
#{colorize(:cyan, 'Description')}
Upload a local file or directory.
#{colorize(:cyan, 'Documentation')}
For documentation see http://pup.pt/bolt-commands.
#{colorize(:cyan, 'Examples')}
bolt file upload /tmp/source /etc/profile.d/login.sh -t target1
HELP
GROUP_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
group
#{colorize(:cyan, 'Usage')}
bolt group <action> [options]
#{colorize(:cyan, 'Description')}
Show the list of groups in the inventory.
#{colorize(:cyan, 'Documentation')}
To learn more about the inventory run 'bolt guide inventory'.
#{colorize(:cyan, 'Actions')}
show Show the list of groups in the inventory
HELP
GROUP_SHOW_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
group show
#{colorize(:cyan, 'Usage')}
bolt group show [options]
#{colorize(:cyan, 'Description')}
Show the list of groups in the inventory.
#{colorize(:cyan, 'Documentation')}
To learn more about the inventory run 'bolt guide inventory'.
HELP
GUIDE_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
guide
#{colorize(:cyan, 'Usage')}
bolt guide [topic] [options]
#{colorize(:cyan, 'Description')}
View guides for Bolt's concepts and features.
Omitting a topic will display a list of available guides,
while providing a topic will display the relevant guide.
#{colorize(:cyan, 'Examples')}
View a list of available guides
bolt guide
View the 'project' guide page
bolt guide project
HELP
INVENTORY_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
inventory
#{colorize(:cyan, 'Usage')}
bolt inventory <action> [options]
#{colorize(:cyan, 'Description')}
Show the list of targets an action would run on.
#{colorize(:cyan, 'Documentation')}
To learn more about the inventory run 'bolt guide inventory'.
#{colorize(:cyan, 'Actions')}
show Show the list of targets an action would run on
HELP
INVENTORY_SHOW_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
inventory show
#{colorize(:cyan, 'Usage')}
bolt inventory show [options]
#{colorize(:cyan, 'Description')}
Show the list of targets an action would run on. This command will list
all targets in the project's inventory by default.
To filter the targets in the list, use the --targets, --query, or --rerun
options. To view detailed configuration and data for targets, use the
--detail option. To learn more about the inventory run 'bolt guide inventory'.
#{colorize(:cyan, 'Documentation')}
To learn more about the inventory run 'bolt guide inventory'.
HELP
LOOKUP_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
lookup
#{colorize(:cyan, 'Usage')}
bolt lookup <key> {--targets TARGETS | --query QUERY | --rerun FILTER | --plan-hierarchy}
[options]
#{colorize(:cyan, 'Description')}
Look up a value with Hiera.
#{colorize(:cyan, 'Documentation')}
Learn more about using Hiera with Bolt at https://pup.pt/bolt-hiera.
#{colorize(:cyan, 'Examples')}
bolt lookup password --targets servers
bolt lookup password --plan-hierarchy variable=value
HELP
MODULE_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
module
#{colorize(:cyan, 'Usage')}
bolt module <action> [options]
#{colorize(:cyan, 'Description')}
Manage Bolt project modules.
#{colorize(:cyan, 'Documentation')}
To learn more about Bolt modules run 'bolt guide module'.
#{colorize(:cyan, 'Actions')}
add Add a module to the project
generate-types Generate type references to register in plans
install Install the project's modules
show List modules available to the Bolt project
HELP
MODULE_ADD_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
module add
#{colorize(:cyan, 'Usage')}
bolt module add <module> [options]
#{colorize(:cyan, 'Description')}
Add a module to the project.
Module declarations are loaded from the project's configuration
file. Bolt will automatically resolve all module dependencies,
generate a Puppetfile, and install the modules.
#{colorize(:cyan, 'Documentation')}
To learn more about Bolt modules, run 'bolt guide module'.
HELP
MODULE_GENERATETYPES_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
module generate-types
#{colorize(:cyan, 'Usage')}
bolt module generate-types [options]
#{colorize(:cyan, 'Description')}
Generate type references to register in plans. To learn more about
Bolt modules, run 'bolt guide module'.
#{colorize(:cyan, 'Documentation')}
To learn more about Bolt modules, run 'bolt guide module'.
HELP
MODULE_INSTALL_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
module install
#{colorize(:cyan, 'Usage')}
bolt module install [options]
#{colorize(:cyan, 'Description')}
Install the project's modules.
Module declarations are loaded from the project's configuration
file. Bolt will automatically resolve all module dependencies,
generate a Puppetfile, and install the modules.
#{colorize(:cyan, 'Documentation')}
To learn more about Bolt modules, run 'bolt guide module'.
HELP
MODULE_SHOW_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
module show
#{colorize(:cyan, 'Usage')}
bolt module show [module name] [options]
#{colorize(:cyan, 'Description')}
List modules available to the Bolt project.
Providing the name of a module will display detailed documentation for
the module.
#{colorize(:cyan, 'Documentation')}
To learn more about Bolt modules, run 'bolt guide module'.
HELP
PLAN_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
plan
#{colorize(:cyan, 'Usage')}
bolt plan <action> [options]
#{colorize(:cyan, 'Description')}
Convert, create, show, and run Bolt plans.
#{colorize(:cyan, 'Documentation')}
Learn more about Bolt plans at https://pup.pt/bolt-plans.
#{colorize(:cyan, 'Actions')}
convert Convert a YAML plan to a Bolt plan
new Create a new plan in the current project
run Run a plan on the specified targets
show Show available plans and plan documentation
HELP
PLAN_CONVERT_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
plan convert
#{colorize(:cyan, 'Usage')}
bolt plan convert <plan name> [options]
#{colorize(:cyan, 'Description')}
Convert a YAML plan to a Puppet language plan and print the converted
plan to stdout.
Converting a YAML plan might result in a plan that is syntactically
correct but has different behavior. Always verify a converted plan's
functionality. Note that the converted plan is not written to a file.
#{colorize(:cyan, 'Documentation')}
Learn more about Bolt plans at https://pup.pt/bolt-plans.
#{colorize(:cyan, 'Examples')}
bolt plan convert myproject::myplan
bolt plan convert path/to/plan/myplan.yaml
HELP
PLAN_NEW_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
plan new
#{colorize(:cyan, 'Usage')}
bolt plan new <plan name> [options]
#{colorize(:cyan, 'Description')}
Create a new plan in the current project.
#{colorize(:cyan, 'Documentation')}
Learn more about Bolt plans at https://pup.pt/bolt-plans.
#{colorize(:cyan, 'Examples')}
bolt plan new myproject::myplan
HELP
PLAN_RUN_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
plan run
#{colorize(:cyan, 'Usage')}
bolt plan run <plan name> [parameters] [options]
#{colorize(:cyan, 'Description')}
Run a plan on the specified targets.
#{colorize(:cyan, 'Documentation')}
Learn more about Bolt plans at https://pup.pt/bolt-plans.
#{colorize(:cyan, 'Examples')}
bolt plan run canary --targets target1,target2 command=hostname
HELP
PLAN_SHOW_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
plan show
#{colorize(:cyan, 'Usage')}
bolt plan show [plan name] [options]
#{colorize(:cyan, 'Description')}
Show available plans and plan documentation.
Omitting the name of a plan will display a list of plans available
in the Bolt project.
Providing the name of a plan will display detailed documentation for
the plan, including a list of available parameters.
#{colorize(:cyan, 'Documentation')}
Learn more about Bolt plans at https://pup.pt/bolt-plans.
#{colorize(:cyan, 'Examples')}
Display a list of available plans
bolt plan show
Display documentation for the aggregate::count plan
bolt plan show aggregate::count
HELP
PLUGIN_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
plugin
#{colorize(:cyan, 'Usage')}
bolt plugin <action> [options]
#{colorize(:cyan, 'Description')}
Show available plugins.
#{colorize(:cyan, 'Documentation')}
Learn more about Bolt plugins at https://pup.pt/bolt-plugins.
#{colorize(:cyan, 'Actions')}
show Show available plugins
HELP
PLUGIN_SHOW_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
plugin show
#{colorize(:cyan, 'Usage')}
bolt plugin show [options]
#{colorize(:cyan, 'Description')}
Show available plugins.
#{colorize(:cyan, 'Documentation')}
Learn more about Bolt plugins at https://pup.pt/bolt-plugins.
HELP
POLICY_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
policy
#{colorize(:cyan, 'Usage')}
bolt policy <action> [options]
#{colorize(:cyan, 'Description')}
Apply, create, and show policies.
#{colorize(:cyan, 'Actions')}
apply Apply a policy to the specified targets
new Create a new policy in the current project
show Show available policy
HELP
POLICY_APPLY_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
policy apply
#{colorize(:cyan, 'Usage')}
bolt policy apply <policy> [options]
#{colorize(:cyan, 'Description')}
Apply a policy to the specified targets.
HELP
POLICY_NEW_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
policy new
#{colorize(:cyan, 'Usage')}
bolt policy new <policy> [options]
#{colorize(:cyan, 'Description')}
Create a new policy in the current project.
HELP
POLICY_SHOW_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
policy show
#{colorize(:cyan, 'Usage')}
bolt policy show [options]
#{colorize(:cyan, 'Description')}
Show available policies.
HELP
PROJECT_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
project
#{colorize(:cyan, 'Usage')}
bolt project <action> [options]
#{colorize(:cyan, 'Description')}
Create and migrate Bolt projects
#{colorize(:cyan, 'Documentation')}
To learn more about Bolt projects, run 'bolt guide project'.
#{colorize(:cyan, 'Actions')}
init Create a new Bolt project
migrate Migrate a Bolt project to the latest version
HELP
PROJECT_INIT_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
project init
#{colorize(:cyan, 'Usage')}
bolt project init [name] [options]
#{colorize(:cyan, 'Description')}
Create a new Bolt project in the current working directory.
Specify a name for the Bolt project. Defaults to the basename of the current working directory.
#{colorize(:cyan, 'Documentation')}
To learn more about Bolt projects, run 'bolt guide project'.
#{colorize(:cyan, 'Examples')}
Create a new Bolt project using the directory as the project name.
bolt project init
Create a new Bolt project with a specified name.
bolt project init myproject
Create a new Bolt project with existing modules.
bolt project init --modules puppetlabs-apt,puppetlabs-ntp
HELP
PROJECT_MIGRATE_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
project migrate
#{colorize(:cyan, 'Usage')}
bolt project migrate [options]
#{colorize(:cyan, 'Description')}
Migrate a Bolt project to use current best practices and the latest version of
configuration files.
#{colorize(:cyan, 'Documentation')}
To learn more about Bolt projects, run 'bolt guide project'.
HELP
SCRIPT_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
script
#{colorize(:cyan, 'Usage')}
bolt script <action> [options]
#{colorize(:cyan, 'Description')}
Run a script on the specified targets.
#{colorize(:cyan, 'Documentation')}
Learn more about running scripts at https://pup.pt/bolt-commands.
#{colorize(:cyan, 'Actions')}
run Run a script on the specified targets.
HELP
SCRIPT_RUN_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
script run
#{colorize(:cyan, 'Usage')}
bolt script run <script> [arguments] {--targets TARGETS | --query QUERY | --rerun FILTER}
[options]
#{colorize(:cyan, 'Description')}
Run a script on the specified targets.
Arguments passed to a script are passed literally and are not interpolated
by the shell. Any arguments containing spaces or special characters should
be quoted.
#{colorize(:cyan, 'Documentation')}
Learn more about running scripts at https://pup.pt/bolt-commands.
#{colorize(:cyan, 'Examples')}
bolt script run myscript.sh 'echo hello' --targets target1,target2
HELP
SECRET_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
secret
#{colorize(:cyan, 'Usage')}
bolt secret <action> [options]
#{colorize(:cyan, 'Description')}
Create encryption keys and encrypt and decrypt values.
#{colorize(:cyan, 'Documentation')}
Learn more about secrets plugins at http://pup.pt/bolt-plugins.
#{colorize(:cyan, 'Actions')}
createkeys Create new encryption keys
encrypt Encrypt a value
decrypt Decrypt a value
HELP
SECRET_CREATEKEYS_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
secret createkeys
#{colorize(:cyan, 'Usage')}
bolt secret createkeys [options]
#{colorize(:cyan, 'Description')}
Create new encryption keys.
#{colorize(:cyan, 'Documentation')}
Learn more about secrets plugins at http://pup.pt/bolt-plugins.
HELP
SECRET_DECRYPT_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
secret decrypt
#{colorize(:cyan, 'Usage')}
bolt secret decrypt <ciphertext> [options]
#{colorize(:cyan, 'Description')}
Decrypt a value.
#{colorize(:cyan, 'Documentation')}
Learn more about secrets plugins at http://pup.pt/bolt-plugins.
HELP
SECRET_ENCRYPT_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
secret encrypt
#{colorize(:cyan, 'Usage')}
bolt secret encrypt <plaintext> [options]
#{colorize(:cyan, 'Description')}
Encrypt a value.
#{colorize(:cyan, 'Documentation')}
Learn more about secrets plugins at http://pup.pt/bolt-plugins.
HELP
TASK_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
task
#{colorize(:cyan, 'Usage')}
bolt task <action> [options]
#{colorize(:cyan, 'Description')}
Show and run Bolt tasks.
#{colorize(:cyan, 'Documentation')}
Learn more about Bolt tasks at http://pup.pt/bolt-tasks.
#{colorize(:cyan, 'Actions')}
run Run a Bolt task
show Show available tasks and task documentation
HELP
TASK_RUN_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
task run
#{colorize(:cyan, 'Usage')}
bolt task run <task name> [parameters] {--targets TARGETS | --query QUERY | --rerun FILTER}
[options]
#{colorize(:cyan, 'Description')}
Run a task on the specified targets.
Parameters take the form parameter=value.
#{colorize(:cyan, 'Documentation')}
Learn more about Bolt tasks at http://pup.pt/bolt-tasks.
#{colorize(:cyan, 'Examples')}
bolt task run package --targets target1,target2 action=status name=bash
HELP
TASK_SHOW_HELP = <<~HELP
#{colorize(:cyan, 'Name')}
task show
#{colorize(:cyan, 'Usage')}
bolt task show [task name] [options]
#{colorize(:cyan, 'Description')}
Show available tasks and task documentation.
Omitting the name of a task will display a list of tasks available
in the Bolt project.
Providing the name of a task will display detailed documentation for
the task, including a list of available parameters.
#{colorize(:cyan, 'Documentation')}
Learn more about Bolt tasks at http://pup.pt/bolt-tasks.
#{colorize(:cyan, 'Examples')}
Display a list of available tasks
bolt task show
Display documentation for the canary task
bolt task show canary
HELP
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