pdk 2.7.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/README.md +2 -48
  4. data/lib/pdk/analytics/client/google_analytics.rb +22 -26
  5. data/lib/pdk/analytics/util.rb +0 -1
  6. data/lib/pdk/analytics.rb +1 -1
  7. data/lib/pdk/bolt.rb +1 -0
  8. data/lib/pdk/cli/build.rb +53 -56
  9. data/lib/pdk/cli/bundle.rb +34 -33
  10. data/lib/pdk/cli/console.rb +136 -134
  11. data/lib/pdk/cli/convert.rb +39 -41
  12. data/lib/pdk/cli/env.rb +49 -47
  13. data/lib/pdk/cli/errors.rb +1 -2
  14. data/lib/pdk/cli/exec/command.rb +23 -29
  15. data/lib/pdk/cli/exec/interactive_command.rb +7 -12
  16. data/lib/pdk/cli/exec.rb +4 -11
  17. data/lib/pdk/cli/exec_group.rb +3 -2
  18. data/lib/pdk/cli/get/config.rb +21 -19
  19. data/lib/pdk/cli/get.rb +15 -13
  20. data/lib/pdk/cli/new/class.rb +22 -22
  21. data/lib/pdk/cli/new/defined_type.rb +22 -22
  22. data/lib/pdk/cli/new/fact.rb +19 -19
  23. data/lib/pdk/cli/new/function.rb +20 -20
  24. data/lib/pdk/cli/new/module.rb +40 -38
  25. data/lib/pdk/cli/new/provider.rb +19 -19
  26. data/lib/pdk/cli/new/task.rb +23 -23
  27. data/lib/pdk/cli/new/test.rb +50 -48
  28. data/lib/pdk/cli/new/transport.rb +18 -18
  29. data/lib/pdk/cli/new.rb +11 -9
  30. data/lib/pdk/cli/release/prep.rb +27 -25
  31. data/lib/pdk/cli/release/publish.rb +39 -37
  32. data/lib/pdk/cli/release.rb +152 -149
  33. data/lib/pdk/cli/remove/config.rb +63 -60
  34. data/lib/pdk/cli/remove.rb +15 -13
  35. data/lib/pdk/cli/set/config.rb +91 -89
  36. data/lib/pdk/cli/set.rb +15 -13
  37. data/lib/pdk/cli/test/unit.rb +71 -69
  38. data/lib/pdk/cli/test.rb +9 -7
  39. data/lib/pdk/cli/update.rb +33 -38
  40. data/lib/pdk/cli/util/command_redirector.rb +10 -1
  41. data/lib/pdk/cli/util/interview.rb +11 -4
  42. data/lib/pdk/cli/util/option_normalizer.rb +2 -4
  43. data/lib/pdk/cli/util/option_validator.rb +7 -9
  44. data/lib/pdk/cli/util/update_manager_printer.rb +4 -4
  45. data/lib/pdk/cli/util.rb +32 -48
  46. data/lib/pdk/cli/validate.rb +98 -96
  47. data/lib/pdk/cli.rb +124 -120
  48. data/lib/pdk/config/ini_file.rb +4 -3
  49. data/lib/pdk/config/ini_file_setting.rb +6 -10
  50. data/lib/pdk/config/json.rb +1 -0
  51. data/lib/pdk/config/json_schema_namespace.rb +5 -10
  52. data/lib/pdk/config/json_schema_setting.rb +3 -5
  53. data/lib/pdk/config/json_with_schema.rb +2 -4
  54. data/lib/pdk/config/namespace.rb +19 -13
  55. data/lib/pdk/config/setting.rb +5 -6
  56. data/lib/pdk/config/task_schema.json +116 -0
  57. data/lib/pdk/config/validator.rb +4 -4
  58. data/lib/pdk/config/yaml.rb +3 -8
  59. data/lib/pdk/config/yaml_with_schema.rb +4 -12
  60. data/lib/pdk/config.rb +47 -51
  61. data/lib/pdk/context/control_repo.rb +3 -2
  62. data/lib/pdk/context/module.rb +2 -2
  63. data/lib/pdk/context/none.rb +2 -2
  64. data/lib/pdk/context.rb +4 -5
  65. data/lib/pdk/control_repo.rb +3 -4
  66. data/lib/pdk/generate/defined_type.rb +3 -3
  67. data/lib/pdk/generate/fact.rb +3 -2
  68. data/lib/pdk/generate/function.rb +5 -4
  69. data/lib/pdk/generate/module.rb +91 -106
  70. data/lib/pdk/generate/provider.rb +5 -4
  71. data/lib/pdk/generate/puppet_class.rb +3 -3
  72. data/lib/pdk/generate/puppet_object.rb +9 -12
  73. data/lib/pdk/generate/task.rb +11 -10
  74. data/lib/pdk/generate/transport.rb +8 -7
  75. data/lib/pdk/generate.rb +1 -1
  76. data/lib/pdk/logger.rb +3 -2
  77. data/lib/pdk/module/build.rb +34 -49
  78. data/lib/pdk/module/convert.rb +13 -22
  79. data/lib/pdk/module/metadata.rb +53 -61
  80. data/lib/pdk/module/release.rb +19 -25
  81. data/lib/pdk/module/update.rb +4 -13
  82. data/lib/pdk/module/update_manager.rb +18 -25
  83. data/lib/pdk/module.rb +1 -1
  84. data/lib/pdk/monkey_patches.rb +268 -0
  85. data/lib/pdk/report/event.rb +12 -37
  86. data/lib/pdk/report.rb +4 -4
  87. data/lib/pdk/template/fetcher/git.rb +7 -8
  88. data/lib/pdk/template/fetcher/local.rb +1 -0
  89. data/lib/pdk/template/fetcher.rb +4 -2
  90. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +4 -9
  91. data/lib/pdk/template/renderer/v1/renderer.rb +19 -20
  92. data/lib/pdk/template/renderer/v1/template_file.rb +4 -8
  93. data/lib/pdk/template/renderer/v1.rb +1 -1
  94. data/lib/pdk/template/renderer.rb +1 -0
  95. data/lib/pdk/template/template_dir.rb +3 -3
  96. data/lib/pdk/template.rb +2 -6
  97. data/lib/pdk/tests/unit.rb +36 -25
  98. data/lib/pdk/util/bundler.rb +10 -14
  99. data/lib/pdk/util/changelog_generator.rb +15 -12
  100. data/lib/pdk/util/env.rb +1 -0
  101. data/lib/pdk/util/filesystem.rb +18 -17
  102. data/lib/pdk/util/git.rb +16 -21
  103. data/lib/pdk/util/json_finder.rb +7 -6
  104. data/lib/pdk/util/puppet_strings.rb +1 -1
  105. data/lib/pdk/util/puppet_version.rb +16 -67
  106. data/lib/pdk/util/ruby_version.rb +9 -13
  107. data/lib/pdk/util/template_uri.rb +17 -29
  108. data/lib/pdk/util/vendored_file.rb +5 -18
  109. data/lib/pdk/util/windows/api_types.rb +70 -64
  110. data/lib/pdk/util/windows/file.rb +31 -27
  111. data/lib/pdk/util/windows/process.rb +59 -61
  112. data/lib/pdk/util/windows/string.rb +19 -12
  113. data/lib/pdk/util.rb +12 -20
  114. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +1 -1
  115. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +25 -25
  116. data/lib/pdk/validate/external_command_validator.rb +6 -1
  117. data/lib/pdk/validate/internal_ruby_validator.rb +5 -4
  118. data/lib/pdk/validate/invokable_validator.rb +30 -20
  119. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +12 -14
  120. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +13 -15
  121. data/lib/pdk/validate/metadata/metadata_validator_group.rb +1 -1
  122. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +16 -18
  123. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +14 -14
  124. data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +1 -1
  125. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +16 -18
  126. data/lib/pdk/validate/puppet/puppet_validator_group.rb +1 -1
  127. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +10 -11
  128. data/lib/pdk/validate/ruby/ruby_validator_group.rb +1 -1
  129. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +19 -24
  130. data/lib/pdk/validate/tasks/tasks_name_validator.rb +11 -13
  131. data/lib/pdk/validate/tasks/tasks_validator_group.rb +1 -1
  132. data/lib/pdk/validate/validator.rb +4 -2
  133. data/lib/pdk/validate/validator_group.rb +6 -3
  134. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +27 -36
  135. data/lib/pdk/validate/yaml/yaml_validator_group.rb +1 -1
  136. data/lib/pdk/validate.rb +6 -6
  137. data/lib/pdk/version.rb +2 -2
  138. data/lib/pdk.rb +12 -12
  139. metadata +27 -35
  140. data/lib/pdk/cli/config/get.rb +0 -26
  141. data/lib/pdk/cli/config.rb +0 -22
  142. data/lib/pdk/cli/module/build.rb +0 -12
  143. data/lib/pdk/cli/module/generate.rb +0 -47
  144. data/lib/pdk/cli/module.rb +0 -14
@@ -1,148 +1,150 @@
1
- module PDK::CLI
2
- @console_cmd = @base_cmd.define_command do
3
- name 'console'
4
- usage 'console [console_options]'
5
- summary '(Experimental) Start a session of the puppet debugger console.'
6
- default_subcommand 'help'
7
- description <<-EOF
8
- The pdk console runs a interactive session of the puppet debugger tool to test out snippets of code, run
9
- language evaluations, datatype prototyping and much more. A virtual playground for your puppet code!
10
- For usage details see the puppet debugger docs at https://docs.puppet-debugger.com.
11
-
12
- EOF
13
-
14
- PDK::CLI.puppet_version_options(self)
15
- PDK::CLI.puppet_dev_option(self)
16
- # we have to skip option parsing because it is expected the user
17
- # will be passing additional args that are passed to the debugger
18
- skip_option_parsing
19
-
20
- # TODO: using -h or --help skips the pdk help and passes to puppet debugger help
21
- run do |_opts, args, _cmd|
22
- require 'pdk/cli/util'
23
- require 'pdk/util'
24
-
25
- PDK::CLI::Util.ensure_in_module!(
26
- message: 'Console can only be run from inside a valid module directory',
27
- log_level: :fatal,
28
- )
29
-
30
- PDK::CLI::Util.module_version_check
31
-
32
- processed_options, processed_args = process_opts(args)
33
-
34
- PDK::CLI::Util.validate_puppet_version_opts(processed_options)
35
-
36
- PDK::CLI::Util.analytics_screen_view('console', args)
37
-
38
- # TODO: figure out if we need to remove default configs set by puppet
39
- # so it is scoped for the module only
40
- # "--environmentpath"...
41
- flags = if PDK::Util.in_module_root?
42
- ["--basemodulepath=#{base_module_path}",
43
- "--modulepath=#{base_module_path}"]
44
- else
45
- []
46
- end
47
- debugger_args = ['debugger'] + processed_args + flags
48
- result = run_in_module(processed_options, debugger_args)
49
-
50
- exit result[:exit_code]
51
- end
52
-
53
- # Logs a fatal message about the gem missing and how to add it
54
- def inform_user_for_missing_gem(gem_name = 'puppet-debugger', version = '~> 0.14')
55
- PDK.logger.fatal(<<-EOF
56
- Your Gemfile is missing the #{gem_name} gem. You can add the missing gem
57
- by updating your #{File.join(PDK::Util.module_root, '.sync.yml')} file with the following
58
- and running pdk update.
59
-
60
- Gemfile:
61
- required:
62
- ":development":
63
- - gem: #{gem_name}
64
- version: \"#{version}\"
65
-
66
- EOF
67
- )
68
- end
1
+ module PDK
2
+ module CLI
3
+ @console_cmd = @base_cmd.define_command do
4
+ name 'console'
5
+ usage 'console [console_options]'
6
+ summary '(Experimental) Start a session of the puppet debugger console.'
7
+ default_subcommand 'help'
8
+ description <<~EOF
9
+ The pdk console runs a interactive session of the puppet debugger tool to test out snippets of code, run
10
+ language evaluations, datatype prototyping and much more. A virtual playground for your puppet code!
11
+ For usage details see the puppet debugger docs at https://docs.puppet-debugger.com.
12
+
13
+ EOF
14
+
15
+ PDK::CLI.puppet_version_options(self)
16
+ PDK::CLI.puppet_dev_option(self)
17
+ # we have to skip option parsing because it is expected the user
18
+ # will be passing additional args that are passed to the debugger
19
+ skip_option_parsing
20
+
21
+ # TODO: using -h or --help skips the pdk help and passes to puppet debugger help
22
+ run do |_opts, args, _cmd|
23
+ require 'pdk/cli/util'
24
+ require 'pdk/util'
25
+
26
+ PDK::CLI::Util.ensure_in_module!(
27
+ message: 'Console can only be run from inside a valid module directory',
28
+ log_level: :fatal
29
+ )
30
+
31
+ PDK::CLI::Util.module_version_check
32
+
33
+ processed_options, processed_args = process_opts(args)
34
+
35
+ PDK::CLI::Util.validate_puppet_version_opts(processed_options)
36
+
37
+ PDK::CLI::Util.analytics_screen_view('console', args)
38
+
39
+ # TODO: figure out if we need to remove default configs set by puppet
40
+ # so it is scoped for the module only
41
+ # "--environmentpath"...
42
+ flags = if PDK::Util.in_module_root?
43
+ ["--basemodulepath=#{base_module_path}",
44
+ "--modulepath=#{base_module_path}"]
45
+ else
46
+ []
47
+ end
48
+ debugger_args = ['debugger'] + processed_args + flags
49
+ result = run_in_module(debugger_args, **processed_options)
50
+
51
+ exit result[:exit_code]
52
+ end
69
53
 
70
- # @return [Boolean] - true if the gem was found in the lockfile
71
- # @param [String] - name of ruby gem to check in bundle lockfile
72
- def gem_in_bundle_lockfile?(gem_name)
73
- require 'bundler'
74
- require 'pdk/util/bundler'
75
-
76
- lock_file_path = PDK::Util::Bundler::BundleHelper.new.gemfile_lock
77
- PDK.logger.debug("Checking lockfile #{lock_file_path} for #{gem_name}")
78
- lock_file = ::Bundler::LockfileParser.new(::Bundler.read_file(lock_file_path))
79
- !lock_file.specs.find { |spec| spec.name.eql?(gem_name) }.nil?
80
- rescue ::Bundler::GemfileNotFound => e
81
- PDK.logger.debug e.message
82
- false
83
- end
54
+ # Logs a fatal message about the gem missing and how to add it
55
+ def inform_user_for_missing_gem(gem_name = 'puppet-debugger', version = '~> 0.14')
56
+ PDK.logger.fatal(<<~EOF
57
+ Your Gemfile is missing the #{gem_name} gem. You can add the missing gem
58
+ by updating your #{File.join(PDK::Util.module_root, '.sync.yml')} file with the following
59
+ and running pdk update.
60
+
61
+ Gemfile:
62
+ required:
63
+ ":development":
64
+ - gem: #{gem_name}
65
+ version: "#{version}"
66
+
67
+ EOF
68
+ )
69
+ end
84
70
 
85
- def check_fixtures_dir
86
- existing_path = base_module_path.split(':').find do |path|
87
- PDK::Util::Filesystem.directory?(path) && Dir.entries(path).length > 2
71
+ # @return [Boolean] - true if the gem was found in the lockfile
72
+ # @param [String] - name of ruby gem to check in bundle lockfile
73
+ def gem_in_bundle_lockfile?(gem_name)
74
+ require 'bundler'
75
+ require 'pdk/util/bundler'
76
+
77
+ lock_file_path = PDK::Util::Bundler::BundleHelper.new.gemfile_lock
78
+ PDK.logger.debug("Checking lockfile #{lock_file_path} for #{gem_name}")
79
+ lock_file = ::Bundler::LockfileParser.new(::Bundler.read_file(lock_file_path))
80
+ !lock_file.specs.find { |spec| spec.name.eql?(gem_name) }.nil?
81
+ rescue ::Bundler::GemfileNotFound => e
82
+ PDK.logger.debug e.message
83
+ false
88
84
  end
89
- PDK.logger.warn 'Module fixtures not found, please run pdk bundle exec rake spec_prep.' unless existing_path
90
- end
91
85
 
92
- # @return [Array] - array of split options [{:"puppet-version"=>"6.9.0"}, ['--loglevel=debug']]
93
- # options are for the pdk and debugger pass through
94
- def process_opts(opts)
95
- args = opts.map do |e|
96
- if e =~ %r{\A-{2}puppet|pe\-version|dev}
97
- value = e.split('=')
98
- (value.count < 2) ? value + [''] : value
86
+ def check_fixtures_dir
87
+ existing_path = base_module_path.split(':').find do |path|
88
+ PDK::Util::Filesystem.directory?(path) && Dir.entries(path).length > 2
99
89
  end
90
+ PDK.logger.warn 'Module fixtures not found, please run pdk bundle exec rake spec_prep.' unless existing_path
100
91
  end
101
- args = args.compact.to_h
102
- # symbolize keys
103
- args = args.inject({}) do |memo, (k, v)| # rubocop:disable Style/EachWithObject
104
- memo[k.sub('--', '').to_sym] = v
105
- memo
106
- end
107
- # pass through all other args that are bound for puppet debugger
108
- processed_args = opts.map { |e| e unless e =~ %r{\A-{2}puppet|pe\-version|dev} }.compact
109
- [args, processed_args]
110
- end
111
92
 
112
- # @param opts [Hash] - the options passed into the CRI command
113
- # @param bundle_args [Array] array of bundle exec args and puppet debugger args
114
- # @return [Hash] - a command result hash
115
- def run_in_module(opts, bundle_args)
116
- require 'pdk/cli/exec'
117
- require 'pdk/cli/exec/interactive_command'
118
- require 'pdk/util/ruby_version'
119
- require 'pdk/util/bundler'
120
-
121
- check_fixtures_dir
122
- output = opts[:debug].nil?
123
- puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts, output)
124
- gemfile_env = PDK::Util::Bundler::BundleHelper.gemfile_env(puppet_env[:gemset])
125
- PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
126
- PDK::Util::RubyVersion.instance(puppet_env[:ruby_version])
127
- PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
128
- unless gem_in_bundle_lockfile?('puppet-debugger')
129
- inform_user_for_missing_gem
130
- return { exit_code: 1 }
93
+ # @return [Array] - array of split options [{:"puppet-version"=>"6.9.0"}, ['--loglevel=debug']]
94
+ # options are for the pdk and debugger pass through
95
+ def process_opts(opts)
96
+ args = opts.map do |e|
97
+ if /\A-{2}puppet|pe-version|dev/.match?(e)
98
+ value = e.split('=')
99
+ value.count < 2 ? value + [''] : value
100
+ end
101
+ end
102
+ args = args.compact.to_h
103
+ # symbolize keys
104
+ args = args.inject({}) do |memo, (k, v)| # rubocop:disable Style/EachWithObject
105
+ memo[k.sub('--', '').to_sym] = v
106
+ memo
107
+ end
108
+ # pass through all other args that are bound for puppet debugger
109
+ processed_args = opts.grep_v(/\A-{2}puppet|pe-version|dev/)
110
+ [args, processed_args]
131
111
  end
132
112
 
133
- debugger_args = %w[exec puppet] + bundle_args
134
- command = PDK::CLI::Exec::InteractiveCommand.new(PDK::CLI::Exec.bundle_bin, *debugger_args).tap do |c|
135
- c.context = :pwd
136
- c.update_environment(gemfile_env)
113
+ # @param opts [Hash] - the options passed into the CRI command
114
+ # @param bundle_args [Array] array of bundle exec args and puppet debugger args
115
+ # @return [Hash] - a command result hash
116
+ def run_in_module(bundle_args, opts)
117
+ require 'pdk/cli/exec'
118
+ require 'pdk/cli/exec/interactive_command'
119
+ require 'pdk/util/ruby_version'
120
+ require 'pdk/util/bundler'
121
+
122
+ check_fixtures_dir
123
+ output = opts[:debug].nil?
124
+ puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts, output)
125
+ gemfile_env = PDK::Util::Bundler::BundleHelper.gemfile_env(puppet_env[:gemset])
126
+ PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
127
+ PDK::Util::RubyVersion.instance(puppet_env[:ruby_version])
128
+ PDK::Util::Bundler.ensure_bundle!(**puppet_env[:gemset])
129
+ unless gem_in_bundle_lockfile?('puppet-debugger')
130
+ inform_user_for_missing_gem
131
+ return { exit_code: 1 }
132
+ end
133
+
134
+ debugger_args = ['exec', 'puppet'] + bundle_args
135
+ command = PDK::CLI::Exec::InteractiveCommand.new(PDK::CLI::Exec.bundle_bin, *debugger_args).tap do |c|
136
+ c.context = :pwd
137
+ c.update_environment(gemfile_env)
138
+ end
139
+ command.execute!
137
140
  end
138
- command.execute!
139
- end
140
141
 
141
- # @return [String] - the basemodulepath of the fixtures and modules from the current module
142
- # also includes ./modules in case librarian puppet is used
143
- def base_module_path
144
- base_module_path = File.join(PDK::Util.module_fixtures_dir, 'modules')
145
- "#{base_module_path}:#{File.join(PDK::Util.module_root, 'modules')}"
142
+ # @return [String] - the basemodulepath of the fixtures and modules from the current module
143
+ # also includes ./modules in case librarian puppet is used
144
+ def base_module_path
145
+ base_module_path = File.join(PDK::Util.module_fixtures_dir, 'modules')
146
+ "#{base_module_path}:#{File.join(PDK::Util.module_root, 'modules')}"
147
+ end
146
148
  end
147
149
  end
148
150
  end
@@ -1,52 +1,50 @@
1
- module PDK::CLI
2
- @convert_cmd = @base_cmd.define_command do
3
- name 'convert'
4
- usage 'convert [options]'
5
- summary 'Convert an existing module to be compatible with the PDK.'
6
-
7
- PDK::CLI.template_url_option(self)
8
- PDK::CLI.template_ref_option(self)
9
- PDK::CLI.skip_interview_option(self)
10
- PDK::CLI.full_interview_option(self)
11
- flag nil, :noop, 'Do not convert the module, just output what would be done.'
12
- flag nil, :force, 'Convert the module automatically, with no prompts.'
13
- flag nil, :'add-tests', 'Add any missing tests while converting the module.'
14
- flag nil, :'default-template', 'Convert the module to use the default PDK template.'
15
-
16
- run do |opts, _args, _cmd|
17
- # Write the context information to the debug log
18
- PDK.context.to_debug_log
19
-
20
- unless PDK.context.is_a?(PDK::Context::Module)
21
- raise PDK::CLI::ExitWithError, '`pdk convert` can only be run from inside a valid module directory.'
22
- end
1
+ module PDK
2
+ module CLI
3
+ @convert_cmd = @base_cmd.define_command do
4
+ name 'convert'
5
+ usage 'convert [options]'
6
+ summary 'Convert an existing module to be compatible with the PDK.'
23
7
 
24
- if opts[:noop] && opts[:force]
25
- raise PDK::CLI::ExitWithError, 'You can not specify --noop and --force when converting a module'
26
- end
8
+ PDK::CLI.template_url_option(self)
9
+ PDK::CLI.template_ref_option(self)
10
+ PDK::CLI.skip_interview_option(self)
11
+ PDK::CLI.full_interview_option(self)
12
+ flag nil, :noop, 'Do not convert the module, just output what would be done.'
13
+ flag nil, :force, 'Convert the module automatically, with no prompts.'
14
+ flag nil, :'add-tests', 'Add any missing tests while converting the module.'
15
+ flag nil, :'default-template', 'Convert the module to use the default PDK template.'
27
16
 
28
- if opts[:'default-template']
29
- raise PDK::CLI::ExitWithError, 'You can not specify --template-url and --default-template.' if opts[:'template-url']
17
+ run do |opts, _args, _cmd|
18
+ # Write the context information to the debug log
19
+ PDK.context.to_debug_log
30
20
 
31
- opts[:'template-url'] = PDK::Util::TemplateURI.default_template_addressable_uri.to_s
32
- PDK.config.set(%w[user module_defaults template-url], nil)
33
- end
21
+ raise PDK::CLI::ExitWithError, '`pdk convert` can only be run from inside a valid module directory.' unless PDK.context.is_a?(PDK::Context::Module)
34
22
 
35
- PDK::CLI::Util.validate_template_opts(opts)
23
+ raise PDK::CLI::ExitWithError, 'You can not specify --noop and --force when converting a module' if opts[:noop] && opts[:force]
36
24
 
37
- PDK::CLI::Util.analytics_screen_view('convert', opts)
25
+ if opts[:'default-template']
26
+ raise PDK::CLI::ExitWithError, 'You can not specify --template-url and --default-template.' if opts[:'template-url']
38
27
 
39
- if opts[:'skip-interview'] && opts[:'full-interview']
40
- PDK.logger.info 'Ignoring --full-interview and continuing with --skip-interview.'
41
- opts[:'full-interview'] = false
42
- end
28
+ opts[:'template-url'] = PDK::Util::TemplateURI.default_template_addressable_uri.to_s
29
+ PDK.config.set(['user', 'module_defaults', 'template-url'], nil)
30
+ end
43
31
 
44
- if opts[:force] && opts[:'full-interview']
45
- PDK.logger.info 'Ignoring --full-interview and continuing with --force.'
46
- opts[:'full-interview'] = false
47
- end
32
+ PDK::CLI::Util.validate_template_opts(opts)
48
33
 
49
- PDK::Module::Convert.invoke(PDK.context.root_path, opts)
34
+ PDK::CLI::Util.analytics_screen_view('convert', opts)
35
+
36
+ if opts[:'skip-interview'] && opts[:'full-interview']
37
+ PDK.logger.info 'Ignoring --full-interview and continuing with --skip-interview.'
38
+ opts[:'full-interview'] = false
39
+ end
40
+
41
+ if opts[:force] && opts[:'full-interview']
42
+ PDK.logger.info 'Ignoring --full-interview and continuing with --force.'
43
+ opts[:'full-interview'] = false
44
+ end
45
+
46
+ PDK::Module::Convert.invoke(PDK.context.root_path, opts)
47
+ end
50
48
  end
51
49
  end
52
50
  end
data/lib/pdk/cli/env.rb CHANGED
@@ -1,51 +1,53 @@
1
- module PDK::CLI
2
- @env_cmd = @base_cmd.define_command do
3
- name 'env'
4
- usage 'env'
5
- summary '(Experimental) Output environment variables for specific Puppet context'
6
- description <<-EOF
7
- [experimental] Aids in setting a CLI context for a specified version of Puppet by outputting export commands for necessary environment variables.
8
- EOF
9
-
10
- PDK::CLI.puppet_version_options(self)
11
- PDK::CLI.puppet_dev_option(self)
12
-
13
- run do |opts, _args, _cmd|
14
- require 'pdk/util'
15
- require 'pdk/util/ruby_version'
16
-
17
- PDK::CLI::Util.validate_puppet_version_opts(opts)
18
-
19
- PDK::CLI::Util.analytics_screen_view('env')
20
-
21
- # Ensure that the correct Ruby is activated before running command.
22
- puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
23
- PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
24
-
25
- resolved_env = {
26
- 'PDK_RESOLVED_PUPPET_VERSION' => puppet_env[:gemset][:puppet],
27
- 'PDK_RESOLVED_RUBY_VERSION' => puppet_env[:ruby_version],
28
- }
29
-
30
- resolved_env['GEM_HOME'] = PDK::Util::RubyVersion.gem_home
31
- gem_path = PDK::Util::RubyVersion.gem_path
32
- resolved_env['GEM_PATH'] = gem_path.empty? ? resolved_env['GEM_HOME'] : gem_path
33
-
34
- # Make sure invocation of Ruby prefers our private installation.
35
- package_binpath = PDK::Util.package_install? ? File.join(PDK::Util.pdk_package_basedir, 'bin') : nil
36
-
37
- resolved_env['PATH'] = [
38
- PDK::Util::RubyVersion.bin_path,
39
- File.join(resolved_env['GEM_HOME'], 'bin'),
40
- PDK::Util::RubyVersion.gem_paths_raw.map { |gem_path_raw| File.join(gem_path_raw, 'bin') },
41
- package_binpath,
42
- PDK::Util::Env['PATH'],
43
- ].compact.flatten.join(File::PATH_SEPARATOR)
44
-
45
- resolved_env.each do |var, val|
46
- puts "export #{var}=\"#{val}\""
1
+ module PDK
2
+ module CLI
3
+ @env_cmd = @base_cmd.define_command do
4
+ name 'env'
5
+ usage 'env'
6
+ summary '(Experimental) Output environment variables for specific Puppet context'
7
+ description <<~EOF
8
+ [experimental] Aids in setting a CLI context for a specified version of Puppet by outputting export commands for necessary environment variables.
9
+ EOF
10
+
11
+ PDK::CLI.puppet_version_options(self)
12
+ PDK::CLI.puppet_dev_option(self)
13
+
14
+ run do |opts, _args, _cmd|
15
+ require 'pdk/util'
16
+ require 'pdk/util/ruby_version'
17
+
18
+ PDK::CLI::Util.validate_puppet_version_opts(opts)
19
+
20
+ PDK::CLI::Util.analytics_screen_view('env')
21
+
22
+ # Ensure that the correct Ruby is activated before running command.
23
+ puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
24
+ PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
25
+
26
+ resolved_env = {
27
+ 'PDK_RESOLVED_PUPPET_VERSION' => puppet_env[:gemset][:puppet],
28
+ 'PDK_RESOLVED_RUBY_VERSION' => puppet_env[:ruby_version]
29
+ }
30
+
31
+ resolved_env['GEM_HOME'] = PDK::Util::RubyVersion.gem_home
32
+ gem_path = PDK::Util::RubyVersion.gem_path
33
+ resolved_env['GEM_PATH'] = gem_path.empty? ? resolved_env['GEM_HOME'] : gem_path
34
+
35
+ # Make sure invocation of Ruby prefers our private installation.
36
+ package_binpath = PDK::Util.package_install? ? File.join(PDK::Util.pdk_package_basedir, 'bin') : nil
37
+
38
+ resolved_env['PATH'] = [
39
+ PDK::Util::RubyVersion.bin_path,
40
+ File.join(resolved_env['GEM_HOME'], 'bin'),
41
+ PDK::Util::RubyVersion.gem_paths_raw.map { |gem_path_raw| File.join(gem_path_raw, 'bin') },
42
+ package_binpath,
43
+ PDK::Util::Env['PATH']
44
+ ].compact.flatten.join(File::PATH_SEPARATOR)
45
+
46
+ resolved_env.each do |var, val|
47
+ puts "export #{var}=\"#{val}\""
48
+ end
49
+ exit 0
47
50
  end
48
- exit 0
49
51
  end
50
52
  end
51
53
  end
@@ -12,8 +12,7 @@ module PDK
12
12
  end
13
13
 
14
14
  class ExitWithError < StandardError
15
- attr_reader :exit_code
16
- attr_reader :log_level
15
+ attr_reader :exit_code, :log_level
17
16
 
18
17
  def initialize(msg, opts = {})
19
18
  @exit_code = opts.fetch(:exit_code, 1)
@@ -4,10 +4,8 @@ module PDK
4
4
  module CLI
5
5
  module Exec
6
6
  class Command
7
- attr_reader :argv
8
- attr_reader :context
9
- attr_accessor :timeout
10
- attr_accessor :environment
7
+ attr_reader :argv, :context
8
+ attr_accessor :timeout, :environment
11
9
  attr_writer :exec_group
12
10
 
13
11
  # The spinner for this command.
@@ -22,6 +20,8 @@ module PDK
22
20
 
23
21
  def initialize(*argv)
24
22
  require 'childprocess'
23
+
24
+ require 'pdk/monkey_patches'
25
25
  require 'tempfile'
26
26
 
27
27
  @argv = argv
@@ -56,9 +56,7 @@ module PDK
56
56
  end
57
57
 
58
58
  def context=(new_context)
59
- unless [:system, :module, :pwd].include?(new_context)
60
- raise ArgumentError, "Expected execution context to be :system or :module but got '%{context}'." % { context: new_context }
61
- end
59
+ raise ArgumentError, format("Expected execution context to be :system or :module but got '%{context}'.", context: new_context) unless [:system, :module, :pwd].include?(new_context)
62
60
 
63
61
  @context = new_context
64
62
  end
@@ -67,6 +65,7 @@ module PDK
67
65
  require 'pdk/cli/util'
68
66
 
69
67
  return unless PDK::CLI::Util.interactive?
68
+
70
69
  @success_message = opts.delete(:success)
71
70
  @failure_message = opts.delete(:failure)
72
71
 
@@ -77,6 +76,7 @@ module PDK
77
76
  require 'pdk/cli/util'
78
77
 
79
78
  return unless PDK::CLI::Util.interactive?
79
+
80
80
  @success_message = opts.delete(:success)
81
81
  @failure_message = opts.delete(:failure)
82
82
 
@@ -96,7 +96,7 @@ module PDK
96
96
  # :duration => Float : Number seconds it took to execute
97
97
  def execute!
98
98
  # Start spinning if configured.
99
- @spinner.auto_spin if @spinner
99
+ @spinner&.auto_spin
100
100
 
101
101
  # Set env for child process
102
102
  resolved_env_for_command.each { |k, v| @process.environment[k] = v }
@@ -106,7 +106,7 @@ module PDK
106
106
  mod_root = PDK::Util.module_root
107
107
 
108
108
  unless mod_root
109
- @spinner.error if @spinner
109
+ @spinner&.error
110
110
 
111
111
  raise PDK::CLI::FatalError, 'Current working directory is not part of a module. (No metadata.json was found.)'
112
112
  end
@@ -132,15 +132,11 @@ module PDK
132
132
  stdout: @stdout.read,
133
133
  stderr: @stderr.read,
134
134
  exit_code: @process.exit_code,
135
- duration: @duration,
135
+ duration: @duration
136
136
  }
137
137
 
138
- PDK.logger.debug 'STDOUT: %{output}' % {
139
- output: process_data[:stdout].empty? ? 'N/A' : "\n#{process_data[:stdout]}",
140
- }
141
- PDK.logger.debug 'STDERR: %{output}' % {
142
- output: process_data[:stderr].empty? ? 'N/A' : "\n#{process_data[:stderr]}",
143
- }
138
+ PDK.logger.debug format('STDOUT: %{output}', output: process_data[:stdout].empty? ? 'N/A' : "\n#{process_data[:stdout]}")
139
+ PDK.logger.debug format('STDERR: %{output}', output: process_data[:stderr].empty? ? 'N/A' : "\n#{process_data[:stderr]}")
144
140
 
145
141
  process_data
146
142
  ensure
@@ -157,10 +153,8 @@ module PDK
157
153
  'or set the PDK_PUPPET_VERSION environment variable instead'
158
154
  end
159
155
 
160
- %w[FACTER HIERA].each do |gem|
161
- if PDK::Util::Env["#{gem}_GEM_VERSION"]
162
- PDK.logger.warn_once '%{varname} is not supported by PDK.' % { varname: "#{gem}_GEM_VERSION" }
163
- end
156
+ ['FACTER', 'HIERA'].each do |gem|
157
+ PDK.logger.warn_once format('%{varname} is not supported by PDK.', varname: "#{gem}_GEM_VERSION") if PDK::Util::Env["#{gem}_GEM_VERSION"]
164
158
  end
165
159
  end
166
160
 
@@ -196,7 +190,7 @@ module PDK
196
190
  PDK::Util::RubyVersion.gem_paths_raw.map { |gem_path_raw| File.join(gem_path_raw, 'bin') },
197
191
  package_binpath,
198
192
  PDK::Util.package_install? ? PDK::Util::Git.git_paths : nil,
199
- PDK::Util::Env['PATH'],
193
+ PDK::Util::Env['PATH']
200
194
  ].compact.flatten.join(File::PATH_SEPARATOR)
201
195
  end
202
196
 
@@ -230,7 +224,7 @@ module PDK
230
224
  def run_process!
231
225
  command_string = argv.join(' ')
232
226
 
233
- PDK.logger.debug("Executing '%{command}'" % { command: command_string })
227
+ PDK.logger.debug(format("Executing '%{command}'", command: command_string))
234
228
 
235
229
  if context == :module
236
230
  PDK.logger.debug('Command environment:')
@@ -244,7 +238,7 @@ module PDK
244
238
  begin
245
239
  @process.start
246
240
  rescue ChildProcess::LaunchError => e
247
- raise PDK::CLI::FatalError, "Failed to execute '%{command}': %{message}" % { command: command_string, message: e.message }
241
+ raise PDK::CLI::FatalError, format("Failed to execute '%{command}': %{message}", command: command_string, message: e.message)
248
242
  end
249
243
 
250
244
  if timeout
@@ -260,13 +254,13 @@ module PDK
260
254
 
261
255
  @duration = Time.now - start_time
262
256
 
263
- PDK.logger.debug("Execution of '%{command}' complete (duration: %{duration_in_seconds}s; exit code: %{exit_code})" %
264
- { command: command_string, duration_in_seconds: @duration, exit_code: @process.exit_code })
257
+ PDK.logger.debug(format("Execution of '%{command}' complete (duration: %{duration_in_seconds}s; exit code: %{exit_code})", command: command_string, duration_in_seconds: @duration,
258
+ exit_code: @process.exit_code))
265
259
  end
266
260
 
267
261
  private
268
262
 
269
- #:nocov:
263
+ # :nocov:
270
264
  # These are just bundler helper methods and are tested via the public run_process_in_clean_env! method
271
265
  def run_process_with_unbundled_env!
272
266
  # Bundler 2.1.0 or greater
@@ -274,9 +268,9 @@ module PDK
274
268
  run_process!
275
269
  end
276
270
  end
277
- #:nocov:
271
+ # :nocov:
278
272
 
279
- #:nocov:
273
+ # :nocov:
280
274
  # These are just bundler helper methods and are tested via the public run_process_in_clean_env! method
281
275
  def run_process_with_clean_env!
282
276
  # Bundler 2.0.2 or less
@@ -284,7 +278,7 @@ module PDK
284
278
  run_process!
285
279
  end
286
280
  end
287
- #:nocov:
281
+ # :nocov:
288
282
  end
289
283
  end
290
284
  end