pdk 2.4.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +803 -1329
  3. data/LICENSE +201 -201
  4. data/README.md +165 -163
  5. data/exe/pdk +10 -10
  6. data/lib/pdk/analytics/client/google_analytics.rb +143 -143
  7. data/lib/pdk/analytics/client/noop.rb +25 -25
  8. data/lib/pdk/analytics/util.rb +19 -19
  9. data/lib/pdk/analytics.rb +30 -30
  10. data/lib/pdk/answer_file.rb +12 -12
  11. data/lib/pdk/bolt.rb +19 -19
  12. data/lib/pdk/cli/build.rb +82 -82
  13. data/lib/pdk/cli/bundle.rb +48 -48
  14. data/lib/pdk/cli/config/get.rb +26 -26
  15. data/lib/pdk/cli/config.rb +22 -22
  16. data/lib/pdk/cli/console.rb +148 -148
  17. data/lib/pdk/cli/convert.rb +52 -52
  18. data/lib/pdk/cli/env.rb +52 -52
  19. data/lib/pdk/cli/errors.rb +25 -25
  20. data/lib/pdk/cli/exec/command.rb +293 -293
  21. data/lib/pdk/cli/exec/interactive_command.rb +114 -114
  22. data/lib/pdk/cli/exec.rb +84 -84
  23. data/lib/pdk/cli/exec_group.rb +104 -104
  24. data/lib/pdk/cli/get/config.rb +24 -24
  25. data/lib/pdk/cli/get.rb +20 -20
  26. data/lib/pdk/cli/module/build.rb +12 -12
  27. data/lib/pdk/cli/module/generate.rb +47 -47
  28. data/lib/pdk/cli/module.rb +14 -14
  29. data/lib/pdk/cli/new/class.rb +32 -32
  30. data/lib/pdk/cli/new/defined_type.rb +32 -32
  31. data/lib/pdk/cli/new/fact.rb +29 -29
  32. data/lib/pdk/cli/new/function.rb +29 -29
  33. data/lib/pdk/cli/new/module.rb +53 -53
  34. data/lib/pdk/cli/new/provider.rb +29 -29
  35. data/lib/pdk/cli/new/task.rb +34 -34
  36. data/lib/pdk/cli/new/test.rb +52 -52
  37. data/lib/pdk/cli/new/transport.rb +27 -27
  38. data/lib/pdk/cli/new.rb +21 -21
  39. data/lib/pdk/cli/release/prep.rb +39 -39
  40. data/lib/pdk/cli/release/publish.rb +50 -50
  41. data/lib/pdk/cli/release.rb +194 -194
  42. data/lib/pdk/cli/remove/config.rb +80 -80
  43. data/lib/pdk/cli/remove.rb +20 -20
  44. data/lib/pdk/cli/set/config.rb +119 -119
  45. data/lib/pdk/cli/set.rb +20 -20
  46. data/lib/pdk/cli/test/unit.rb +90 -90
  47. data/lib/pdk/cli/test.rb +11 -11
  48. data/lib/pdk/cli/update.rb +64 -64
  49. data/lib/pdk/cli/util/command_redirector.rb +27 -27
  50. data/lib/pdk/cli/util/interview.rb +72 -72
  51. data/lib/pdk/cli/util/option_normalizer.rb +55 -55
  52. data/lib/pdk/cli/util/option_validator.rb +68 -68
  53. data/lib/pdk/cli/util/spinner.rb +13 -13
  54. data/lib/pdk/cli/util/update_manager_printer.rb +82 -82
  55. data/lib/pdk/cli/util.rb +305 -305
  56. data/lib/pdk/cli/validate.rb +116 -116
  57. data/lib/pdk/cli.rb +175 -175
  58. data/lib/pdk/config/analytics_schema.json +26 -26
  59. data/lib/pdk/config/errors.rb +5 -5
  60. data/lib/pdk/config/ini_file.rb +183 -183
  61. data/lib/pdk/config/ini_file_setting.rb +39 -39
  62. data/lib/pdk/config/json.rb +34 -34
  63. data/lib/pdk/config/json_schema_namespace.rb +142 -142
  64. data/lib/pdk/config/json_schema_setting.rb +53 -53
  65. data/lib/pdk/config/json_with_schema.rb +49 -49
  66. data/lib/pdk/config/namespace.rb +354 -354
  67. data/lib/pdk/config/setting.rb +135 -135
  68. data/lib/pdk/config/validator.rb +31 -31
  69. data/lib/pdk/config/yaml.rb +46 -46
  70. data/lib/pdk/config/yaml_with_schema.rb +59 -59
  71. data/lib/pdk/config.rb +390 -390
  72. data/lib/pdk/context/control_repo.rb +60 -60
  73. data/lib/pdk/context/module.rb +28 -28
  74. data/lib/pdk/context/none.rb +22 -22
  75. data/lib/pdk/context.rb +99 -99
  76. data/lib/pdk/control_repo.rb +90 -90
  77. data/lib/pdk/generate/defined_type.rb +43 -43
  78. data/lib/pdk/generate/fact.rb +25 -25
  79. data/lib/pdk/generate/function.rb +48 -48
  80. data/lib/pdk/generate/module.rb +352 -352
  81. data/lib/pdk/generate/provider.rb +28 -28
  82. data/lib/pdk/generate/puppet_class.rb +43 -43
  83. data/lib/pdk/generate/puppet_object.rb +232 -232
  84. data/lib/pdk/generate/task.rb +68 -68
  85. data/lib/pdk/generate/transport.rb +33 -33
  86. data/lib/pdk/generate.rb +24 -24
  87. data/lib/pdk/i18n.rb +4 -4
  88. data/lib/pdk/logger.rb +45 -45
  89. data/lib/pdk/module/build.rb +322 -322
  90. data/lib/pdk/module/convert.rb +296 -296
  91. data/lib/pdk/module/metadata.rb +202 -202
  92. data/lib/pdk/module/release.rb +260 -260
  93. data/lib/pdk/module/update.rb +131 -131
  94. data/lib/pdk/module/update_manager.rb +227 -227
  95. data/lib/pdk/module.rb +30 -30
  96. data/lib/pdk/report/event.rb +370 -370
  97. data/lib/pdk/report.rb +121 -121
  98. data/lib/pdk/template/fetcher/git.rb +85 -85
  99. data/lib/pdk/template/fetcher/local.rb +28 -28
  100. data/lib/pdk/template/fetcher.rb +98 -98
  101. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -116
  102. data/lib/pdk/template/renderer/v1/renderer.rb +132 -132
  103. data/lib/pdk/template/renderer/v1/template_file.rb +102 -102
  104. data/lib/pdk/template/renderer/v1.rb +25 -25
  105. data/lib/pdk/template/renderer.rb +96 -96
  106. data/lib/pdk/template/template_dir.rb +67 -67
  107. data/lib/pdk/template.rb +59 -59
  108. data/lib/pdk/tests/unit.rb +252 -252
  109. data/lib/pdk/util/bundler.rb +259 -259
  110. data/lib/pdk/util/changelog_generator.rb +137 -137
  111. data/lib/pdk/util/env.rb +47 -47
  112. data/lib/pdk/util/filesystem.rb +138 -138
  113. data/lib/pdk/util/git.rb +179 -179
  114. data/lib/pdk/util/json_finder.rb +85 -85
  115. data/lib/pdk/util/puppet_strings.rb +125 -125
  116. data/lib/pdk/util/puppet_version.rb +266 -266
  117. data/lib/pdk/util/ruby_version.rb +179 -179
  118. data/lib/pdk/util/template_uri.rb +295 -295
  119. data/lib/pdk/util/vendored_file.rb +93 -93
  120. data/lib/pdk/util/version.rb +43 -43
  121. data/lib/pdk/util/windows/api_types.rb +82 -82
  122. data/lib/pdk/util/windows/file.rb +36 -36
  123. data/lib/pdk/util/windows/process.rb +79 -79
  124. data/lib/pdk/util/windows/string.rb +16 -16
  125. data/lib/pdk/util/windows.rb +15 -15
  126. data/lib/pdk/util.rb +278 -278
  127. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -23
  128. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -98
  129. data/lib/pdk/validate/external_command_validator.rb +208 -208
  130. data/lib/pdk/validate/internal_ruby_validator.rb +100 -100
  131. data/lib/pdk/validate/invokable_validator.rb +228 -228
  132. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -86
  133. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -78
  134. data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -20
  135. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -133
  136. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -66
  137. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -137
  138. data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -21
  139. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -80
  140. data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -19
  141. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -88
  142. data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -50
  143. data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -20
  144. data/lib/pdk/validate/validator.rb +118 -118
  145. data/lib/pdk/validate/validator_group.rb +104 -104
  146. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -95
  147. data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -19
  148. data/lib/pdk/validate.rb +94 -94
  149. data/lib/pdk/version.rb +4 -4
  150. data/lib/pdk.rb +76 -76
  151. data/locales/config.yaml +21 -21
  152. data/locales/pdk.pot +2111 -2094
  153. metadata +3 -3
@@ -1,114 +1,114 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module CLI
5
- module Exec
6
- class InteractiveCommand < Command
7
- def initialize(*argv)
8
- @argv = argv
9
-
10
- # Default to running things in the system context.
11
- @context = :system
12
-
13
- # Extra environment vars to add to base set.
14
- @environment = {}
15
- end
16
-
17
- def register_spinner(_spinner, _opts = {})
18
- raise _('This method is not implemented for PDK::CLI::Exec::InteractiveCommand')
19
- end
20
-
21
- def add_spinner(_message, _opts = {})
22
- raise _('This method is not implemented for PDK::CLI::Exec::InteractiveCommand')
23
- end
24
-
25
- def timeout
26
- raise _('This method is not implemented for PDK::CLI::Exec::InteractiveCommand')
27
- end
28
-
29
- def timeout=(_val)
30
- raise _('This method is not implemented for PDK::CLI::Exec::InteractiveCommand')
31
- end
32
-
33
- def exec_group=(_val)
34
- raise _('This method is not implemented for PDK::CLI::Exec::InteractiveCommand')
35
- end
36
-
37
- def execute!
38
- require 'pdk/util'
39
-
40
- @resolved_env = resolved_env_for_command
41
-
42
- if [:module, :pwd].include?(context)
43
- mod_root = PDK::Util.module_root
44
-
45
- unless mod_root
46
- raise PDK::CLI::FatalError, _('Current working directory is not part of a module. (No metadata.json was found.)')
47
- end
48
-
49
- unless context == :pwd || Dir.pwd == mod_root
50
- orig_workdir = Dir.pwd
51
- Dir.chdir(mod_root)
52
- end
53
-
54
- result = run_process_in_clean_env!
55
- else
56
- result = run_process!
57
- end
58
-
59
- {
60
- interactive: true,
61
- stdout: nil,
62
- stderr: nil,
63
- exit_code: result[:exit_code],
64
- duration: result[:duration],
65
- }
66
- ensure
67
- Dir.chdir(orig_workdir) if orig_workdir
68
- end
69
-
70
- protected
71
-
72
- # TODO: debug logging
73
- def run_process!
74
- command_string = argv.join(' ')
75
- PDK.logger.debug(_("Executing '%{command}' interactively") % { command: command_string })
76
-
77
- if context == :module
78
- PDK.logger.debug(_('Command environment:'))
79
- @resolved_env.each do |var, val|
80
- PDK.logger.debug(" #{var}: #{val}")
81
- end
82
- end
83
-
84
- start_time = Time.now
85
-
86
- system(@resolved_env, *argv)
87
-
88
- exit_code = child_status.exitstatus
89
- duration = Time.now - start_time
90
-
91
- PDK.logger.debug(_("Execution of '%{command}' complete (duration: \
92
- %{duration_in_seconds}s; exit code: %{exit_code})") %
93
- {
94
- command: command_string,
95
- exit_code: exit_code,
96
- duration_in_seconds: duration,
97
- })
98
-
99
- { exit_code: exit_code, duration: duration }
100
- end
101
-
102
- def child_status
103
- require 'English'
104
-
105
- $CHILD_STATUS
106
- end
107
-
108
- def stop_spinner
109
- raise _('This method is not implemented for PDK::CLI::Exec::InteractiveCommand')
110
- end
111
- end
112
- end
113
- end
114
- end
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module CLI
5
+ module Exec
6
+ class InteractiveCommand < Command
7
+ def initialize(*argv)
8
+ @argv = argv
9
+
10
+ # Default to running things in the system context.
11
+ @context = :system
12
+
13
+ # Extra environment vars to add to base set.
14
+ @environment = {}
15
+ end
16
+
17
+ def register_spinner(_spinner, _opts = {})
18
+ raise _('This method is not implemented for PDK::CLI::Exec::InteractiveCommand')
19
+ end
20
+
21
+ def add_spinner(_message, _opts = {})
22
+ raise _('This method is not implemented for PDK::CLI::Exec::InteractiveCommand')
23
+ end
24
+
25
+ def timeout
26
+ raise _('This method is not implemented for PDK::CLI::Exec::InteractiveCommand')
27
+ end
28
+
29
+ def timeout=(_val)
30
+ raise _('This method is not implemented for PDK::CLI::Exec::InteractiveCommand')
31
+ end
32
+
33
+ def exec_group=(_val)
34
+ raise _('This method is not implemented for PDK::CLI::Exec::InteractiveCommand')
35
+ end
36
+
37
+ def execute!
38
+ require 'pdk/util'
39
+
40
+ @resolved_env = resolved_env_for_command
41
+
42
+ if [:module, :pwd].include?(context)
43
+ mod_root = PDK::Util.module_root
44
+
45
+ unless mod_root
46
+ raise PDK::CLI::FatalError, _('Current working directory is not part of a module. (No metadata.json was found.)')
47
+ end
48
+
49
+ unless context == :pwd || Dir.pwd == mod_root
50
+ orig_workdir = Dir.pwd
51
+ Dir.chdir(mod_root)
52
+ end
53
+
54
+ result = run_process_in_clean_env!
55
+ else
56
+ result = run_process!
57
+ end
58
+
59
+ {
60
+ interactive: true,
61
+ stdout: nil,
62
+ stderr: nil,
63
+ exit_code: result[:exit_code],
64
+ duration: result[:duration],
65
+ }
66
+ ensure
67
+ Dir.chdir(orig_workdir) if orig_workdir
68
+ end
69
+
70
+ protected
71
+
72
+ # TODO: debug logging
73
+ def run_process!
74
+ command_string = argv.join(' ')
75
+ PDK.logger.debug(_("Executing '%{command}' interactively") % { command: command_string })
76
+
77
+ if context == :module
78
+ PDK.logger.debug(_('Command environment:'))
79
+ @resolved_env.each do |var, val|
80
+ PDK.logger.debug(" #{var}: #{val}")
81
+ end
82
+ end
83
+
84
+ start_time = Time.now
85
+
86
+ system(@resolved_env, *argv)
87
+
88
+ exit_code = child_status.exitstatus
89
+ duration = Time.now - start_time
90
+
91
+ PDK.logger.debug(_("Execution of '%{command}' complete (duration: \
92
+ %{duration_in_seconds}s; exit code: %{exit_code})") %
93
+ {
94
+ command: command_string,
95
+ exit_code: exit_code,
96
+ duration_in_seconds: duration,
97
+ })
98
+
99
+ { exit_code: exit_code, duration: duration }
100
+ end
101
+
102
+ def child_status
103
+ require 'English'
104
+
105
+ $CHILD_STATUS
106
+ end
107
+
108
+ def stop_spinner
109
+ raise _('This method is not implemented for PDK::CLI::Exec::InteractiveCommand')
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
data/lib/pdk/cli/exec.rb CHANGED
@@ -1,84 +1,84 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module CLI
5
- module Exec
6
- autoload :Command, 'pdk/cli/exec/command'
7
- autoload :InteractiveCommand, 'pdk/cli/exec/interactive_command'
8
-
9
- def self.execute(*cmd)
10
- require 'pdk/cli/exec/command'
11
-
12
- Command.new(*cmd).execute!
13
- end
14
-
15
- def self.execute_with_env(env, *cmd)
16
- require 'pdk/cli/exec/command'
17
-
18
- Command.new(*cmd).tap { |c| c.environment = env }.execute!
19
- end
20
-
21
- def self.execute_interactive(*cmd)
22
- require 'pdk/cli/exec/interactive_command'
23
-
24
- InteractiveCommand.new(*cmd).execute!
25
- end
26
-
27
- def self.execute_interactive_with_env(env, *cmd)
28
- require 'pdk/cli/exec/interactive_command'
29
-
30
- InteractiveCommand.new(*cmd).tap { |c| c.environment = env }.execute!
31
- end
32
-
33
- def self.ensure_bin_present!(bin_path, bin_name)
34
- require 'tty-which'
35
-
36
- message = _('Unable to find `%{name}`. Check that it is installed and try again.') % {
37
- name: bin_name,
38
- }
39
-
40
- raise PDK::CLI::FatalError, message unless TTY::Which.exist?(bin_path)
41
- end
42
-
43
- def self.bundle(*args)
44
- ensure_bin_present!(bundle_bin, 'bundler')
45
-
46
- execute(bundle_bin, *args)
47
- end
48
-
49
- def self.bundle_bin
50
- require 'pdk/util/ruby_version'
51
-
52
- bundle_bin = Gem.win_platform? ? 'bundle.bat' : 'bundle'
53
- vendored_bin_path = File.join('private', 'ruby', PDK::Util::RubyVersion.active_ruby_version, 'bin', bundle_bin)
54
-
55
- try_vendored_bin(vendored_bin_path, bundle_bin)
56
- end
57
-
58
- def self.try_vendored_bin(vendored_bin_path, fallback)
59
- require 'pdk/util'
60
-
61
- unless PDK::Util.package_install?
62
- PDK.logger.debug(_("PDK package installation not found. Trying '%{fallback}' from the system PATH instead.") % {
63
- fallback: fallback,
64
- })
65
- return fallback
66
- end
67
-
68
- vendored_bin_full_path = File.join(PDK::Util.pdk_package_basedir, vendored_bin_path)
69
-
70
- require 'pdk/util/filesystem'
71
- unless PDK::Util::Filesystem.exist?(vendored_bin_full_path)
72
- PDK.logger.debug(_("Could not find '%{vendored_bin}' in PDK package. Trying '%{fallback}' from the system PATH instead.") % {
73
- fallback: fallback,
74
- vendored_bin: vendored_bin_full_path,
75
- })
76
- return fallback
77
- end
78
-
79
- PDK.logger.debug(_("Using '%{vendored_bin}' from PDK package.") % { vendored_bin: vendored_bin_full_path })
80
- vendored_bin_full_path
81
- end
82
- end
83
- end
84
- end
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module CLI
5
+ module Exec
6
+ autoload :Command, 'pdk/cli/exec/command'
7
+ autoload :InteractiveCommand, 'pdk/cli/exec/interactive_command'
8
+
9
+ def self.execute(*cmd)
10
+ require 'pdk/cli/exec/command'
11
+
12
+ Command.new(*cmd).execute!
13
+ end
14
+
15
+ def self.execute_with_env(env, *cmd)
16
+ require 'pdk/cli/exec/command'
17
+
18
+ Command.new(*cmd).tap { |c| c.environment = env }.execute!
19
+ end
20
+
21
+ def self.execute_interactive(*cmd)
22
+ require 'pdk/cli/exec/interactive_command'
23
+
24
+ InteractiveCommand.new(*cmd).execute!
25
+ end
26
+
27
+ def self.execute_interactive_with_env(env, *cmd)
28
+ require 'pdk/cli/exec/interactive_command'
29
+
30
+ InteractiveCommand.new(*cmd).tap { |c| c.environment = env }.execute!
31
+ end
32
+
33
+ def self.ensure_bin_present!(bin_path, bin_name)
34
+ require 'tty-which'
35
+
36
+ message = _('Unable to find `%{name}`. Check that it is installed and try again.') % {
37
+ name: bin_name,
38
+ }
39
+
40
+ raise PDK::CLI::FatalError, message unless TTY::Which.exist?(bin_path)
41
+ end
42
+
43
+ def self.bundle(*args)
44
+ ensure_bin_present!(bundle_bin, 'bundler')
45
+
46
+ execute(bundle_bin, *args)
47
+ end
48
+
49
+ def self.bundle_bin
50
+ require 'pdk/util/ruby_version'
51
+
52
+ bundle_bin = Gem.win_platform? ? 'bundle.bat' : 'bundle'
53
+ vendored_bin_path = File.join('private', 'ruby', PDK::Util::RubyVersion.active_ruby_version, 'bin', bundle_bin)
54
+
55
+ try_vendored_bin(vendored_bin_path, bundle_bin)
56
+ end
57
+
58
+ def self.try_vendored_bin(vendored_bin_path, fallback)
59
+ require 'pdk/util'
60
+
61
+ unless PDK::Util.package_install?
62
+ PDK.logger.debug(_("PDK package installation not found. Trying '%{fallback}' from the system PATH instead.") % {
63
+ fallback: fallback,
64
+ })
65
+ return fallback
66
+ end
67
+
68
+ vendored_bin_full_path = File.join(PDK::Util.pdk_package_basedir, vendored_bin_path)
69
+
70
+ require 'pdk/util/filesystem'
71
+ unless PDK::Util::Filesystem.exist?(vendored_bin_full_path)
72
+ PDK.logger.debug(_("Could not find '%{vendored_bin}' in PDK package. Trying '%{fallback}' from the system PATH instead.") % {
73
+ fallback: fallback,
74
+ vendored_bin: vendored_bin_full_path,
75
+ })
76
+ return fallback
77
+ end
78
+
79
+ PDK.logger.debug(_("Using '%{vendored_bin}' from PDK package.") % { vendored_bin: vendored_bin_full_path })
80
+ vendored_bin_full_path
81
+ end
82
+ end
83
+ end
84
+ end
@@ -1,104 +1,104 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module CLI
5
- class ExecGroup
6
- # Execution Group (ExecGroup) factory.
7
- #
8
- # @param message [String] A name or message for this group. Provided for backwards compatibility during refactor
9
- #
10
- # @param create_options [Hash] A hash options used during creation of the ExecGroup. This are not passed to the new object
11
- # @option create_options :parallel [Boolean] Whether the group should be executed in Parallel (True) or Serial (False)
12
- #
13
- # @param group_opts [Hash] A hash of options used to configure the execution group. Provided for backwards compatibility during refactor
14
- #
15
- # @return [ExecGroup]
16
- def self.create(message, create_options = {}, group_opts = {})
17
- if create_options[:parallel]
18
- ParallelExecGroup.new(message, group_opts)
19
- else
20
- SerialExecGroup.new(message, group_opts)
21
- end
22
- end
23
-
24
- # Base class for an Exection Group
25
- #
26
- # @param message [String] A name or message for this group. Provided for backwards compatibility during refactor
27
- #
28
- # @param opts [Hash] A hash of options used to configure the execution group. Provided for backwards compatibility during refactor
29
- #
30
- # @api private
31
- def initialize(_message, opts = {})
32
- @options = opts
33
- end
34
-
35
- # Register something to execute as a group
36
- #
37
- # @param block [Block] A block of ruby to execute
38
- #
39
- # @api private
40
- def register(&_block)
41
- raise PDK::CLI::FatalError, _('No block registered') unless block_given?
42
- end
43
-
44
- # The return code of running all registered blocks
45
- #
46
- # @return [int] The highest exit code from the blocks
47
- #
48
- # @abstract
49
- def exit_code; end
50
- end
51
-
52
- # Executes registered blocks in serial
53
- #
54
- # @see PDK::CLI::ExecGroup
55
- class SerialExecGroup < ExecGroup
56
- def initialize(message, opts = {})
57
- super(message, opts)
58
- @procs = []
59
- end
60
-
61
- def register(&block)
62
- super(&block)
63
-
64
- @procs << block
65
- end
66
-
67
- def exit_code
68
- exit_codes = @procs.map(&:call)
69
- exit_codes.nil? ? 0 : exit_codes.max
70
- end
71
- end
72
-
73
- # Executes registered blocks in parallel using Ruby threads
74
- #
75
- # @see PDK::CLI::ExecGroup
76
- class ParallelExecGroup < ExecGroup
77
- def initialize(message, opts = {})
78
- super(message, opts)
79
- @threads = []
80
- @exit_codes = []
81
- end
82
-
83
- def register(&block)
84
- super(&block)
85
-
86
- # TODO: This executes the thread immediately, whereas the SerialExecGroup executes only when exit_code
87
- # is called. Need to change this so it uses a kind of ThreadPool to limit to number on concurrent jobs
88
- # and only starts on the call to exit_code
89
- # e.g. max_threads = No. of CPUs
90
- @threads << Thread.new do
91
- GettextSetup.initialize(File.absolute_path('../../../locales', File.dirname(__FILE__)))
92
- GettextSetup.negotiate_locale!(GettextSetup.candidate_locales)
93
- @exit_codes << yield
94
- end
95
- end
96
-
97
- def exit_code
98
- @threads.each(&:join)
99
- return 0 if @exit_codes.empty?
100
- @exit_codes.max
101
- end
102
- end
103
- end
104
- end
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module CLI
5
+ class ExecGroup
6
+ # Execution Group (ExecGroup) factory.
7
+ #
8
+ # @param message [String] A name or message for this group. Provided for backwards compatibility during refactor
9
+ #
10
+ # @param create_options [Hash] A hash options used during creation of the ExecGroup. This are not passed to the new object
11
+ # @option create_options :parallel [Boolean] Whether the group should be executed in Parallel (True) or Serial (False)
12
+ #
13
+ # @param group_opts [Hash] A hash of options used to configure the execution group. Provided for backwards compatibility during refactor
14
+ #
15
+ # @return [ExecGroup]
16
+ def self.create(message, create_options = {}, group_opts = {})
17
+ if create_options[:parallel]
18
+ ParallelExecGroup.new(message, group_opts)
19
+ else
20
+ SerialExecGroup.new(message, group_opts)
21
+ end
22
+ end
23
+
24
+ # Base class for an Exection Group
25
+ #
26
+ # @param message [String] A name or message for this group. Provided for backwards compatibility during refactor
27
+ #
28
+ # @param opts [Hash] A hash of options used to configure the execution group. Provided for backwards compatibility during refactor
29
+ #
30
+ # @api private
31
+ def initialize(_message, opts = {})
32
+ @options = opts
33
+ end
34
+
35
+ # Register something to execute as a group
36
+ #
37
+ # @param block [Block] A block of ruby to execute
38
+ #
39
+ # @api private
40
+ def register(&_block)
41
+ raise PDK::CLI::FatalError, _('No block registered') unless block_given?
42
+ end
43
+
44
+ # The return code of running all registered blocks
45
+ #
46
+ # @return [int] The highest exit code from the blocks
47
+ #
48
+ # @abstract
49
+ def exit_code; end
50
+ end
51
+
52
+ # Executes registered blocks in serial
53
+ #
54
+ # @see PDK::CLI::ExecGroup
55
+ class SerialExecGroup < ExecGroup
56
+ def initialize(message, opts = {})
57
+ super(message, opts)
58
+ @procs = []
59
+ end
60
+
61
+ def register(&block)
62
+ super(&block)
63
+
64
+ @procs << block
65
+ end
66
+
67
+ def exit_code
68
+ exit_codes = @procs.map(&:call)
69
+ exit_codes.nil? ? 0 : exit_codes.max
70
+ end
71
+ end
72
+
73
+ # Executes registered blocks in parallel using Ruby threads
74
+ #
75
+ # @see PDK::CLI::ExecGroup
76
+ class ParallelExecGroup < ExecGroup
77
+ def initialize(message, opts = {})
78
+ super(message, opts)
79
+ @threads = []
80
+ @exit_codes = []
81
+ end
82
+
83
+ def register(&block)
84
+ super(&block)
85
+
86
+ # TODO: This executes the thread immediately, whereas the SerialExecGroup executes only when exit_code
87
+ # is called. Need to change this so it uses a kind of ThreadPool to limit to number on concurrent jobs
88
+ # and only starts on the call to exit_code
89
+ # e.g. max_threads = No. of CPUs
90
+ @threads << Thread.new do
91
+ GettextSetup.initialize(File.absolute_path('../../../locales', File.dirname(__FILE__)))
92
+ GettextSetup.negotiate_locale!(GettextSetup.candidate_locales)
93
+ @exit_codes << yield
94
+ end
95
+ end
96
+
97
+ def exit_code
98
+ @threads.each(&:join)
99
+ return 0 if @exit_codes.empty?
100
+ @exit_codes.max
101
+ end
102
+ end
103
+ end
104
+ end
@@ -1,24 +1,24 @@
1
- module PDK::CLI
2
- @get_config_cmd = @get_cmd.define_command do
3
- name 'config'
4
- usage _('config [name]')
5
- summary _('Retrieve the configuration for <name>. If not specified, retrieve all configuration settings')
6
-
7
- run do |_opts, args, _cmd|
8
- item_name = args[0]
9
- resolved_config = PDK.config.resolve(item_name)
10
- # If the user wanted to know a setting but it doesn't exist, raise an error
11
- if resolved_config.empty? && !item_name.nil?
12
- PDK.logger.error(_("Configuration item '%{name}' does not exist") % { name: item_name })
13
- exit 1
14
- end
15
- # If the user requested a setting and it's the only one resolved, then just output the value
16
- if resolved_config.count == 1 && resolved_config.keys[0] == item_name
17
- puts _('%{value}') % { value: resolved_config.values[0] }
18
- exit 0
19
- end
20
- # Otherwise just output everything
21
- resolved_config.keys.sort.each { |key| puts _('%{name}=%{value}') % { name: key, value: resolved_config[key] } }
22
- end
23
- end
24
- end
1
+ module PDK::CLI
2
+ @get_config_cmd = @get_cmd.define_command do
3
+ name 'config'
4
+ usage _('config [name]')
5
+ summary _('Retrieve the configuration for <name>. If not specified, retrieve all configuration settings')
6
+
7
+ run do |_opts, args, _cmd|
8
+ item_name = args[0]
9
+ resolved_config = PDK.config.resolve(item_name)
10
+ # If the user wanted to know a setting but it doesn't exist, raise an error
11
+ if resolved_config.empty? && !item_name.nil?
12
+ PDK.logger.error(_("Configuration item '%{name}' does not exist") % { name: item_name })
13
+ exit 1
14
+ end
15
+ # If the user requested a setting and it's the only one resolved, then just output the value
16
+ if resolved_config.count == 1 && resolved_config.keys[0] == item_name
17
+ puts _('%{value}') % { value: resolved_config.values[0] }
18
+ exit 0
19
+ end
20
+ # Otherwise just output everything
21
+ resolved_config.keys.sort.each { |key| puts _('%{name}=%{value}') % { name: key, value: resolved_config[key] } }
22
+ end
23
+ end
24
+ end