pdk 2.7.1 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -0
- data/README.md +10 -50
- data/lib/pdk/analytics/client/google_analytics.rb +22 -26
- data/lib/pdk/analytics/util.rb +0 -1
- data/lib/pdk/analytics.rb +1 -1
- data/lib/pdk/bolt.rb +1 -0
- data/lib/pdk/cli/build.rb +53 -56
- data/lib/pdk/cli/bundle.rb +34 -33
- data/lib/pdk/cli/console.rb +136 -134
- data/lib/pdk/cli/convert.rb +39 -41
- data/lib/pdk/cli/env.rb +49 -47
- data/lib/pdk/cli/errors.rb +1 -2
- data/lib/pdk/cli/exec/command.rb +23 -29
- data/lib/pdk/cli/exec/interactive_command.rb +7 -12
- data/lib/pdk/cli/exec.rb +4 -11
- data/lib/pdk/cli/exec_group.rb +3 -2
- data/lib/pdk/cli/get/config.rb +21 -19
- data/lib/pdk/cli/get.rb +15 -13
- data/lib/pdk/cli/new/class.rb +22 -22
- data/lib/pdk/cli/new/defined_type.rb +22 -22
- data/lib/pdk/cli/new/fact.rb +19 -19
- data/lib/pdk/cli/new/function.rb +20 -20
- data/lib/pdk/cli/new/module.rb +40 -38
- data/lib/pdk/cli/new/provider.rb +19 -19
- data/lib/pdk/cli/new/task.rb +23 -23
- data/lib/pdk/cli/new/test.rb +50 -48
- data/lib/pdk/cli/new/transport.rb +18 -18
- data/lib/pdk/cli/new.rb +11 -9
- data/lib/pdk/cli/release/prep.rb +27 -25
- data/lib/pdk/cli/release/publish.rb +39 -37
- data/lib/pdk/cli/release.rb +152 -149
- data/lib/pdk/cli/remove/config.rb +63 -60
- data/lib/pdk/cli/remove.rb +15 -13
- data/lib/pdk/cli/set/config.rb +91 -89
- data/lib/pdk/cli/set.rb +15 -13
- data/lib/pdk/cli/test/unit.rb +71 -69
- data/lib/pdk/cli/test.rb +9 -7
- data/lib/pdk/cli/update.rb +33 -38
- data/lib/pdk/cli/util/command_redirector.rb +10 -1
- data/lib/pdk/cli/util/interview.rb +11 -4
- data/lib/pdk/cli/util/option_normalizer.rb +3 -5
- data/lib/pdk/cli/util/option_validator.rb +7 -9
- data/lib/pdk/cli/util/update_manager_printer.rb +4 -4
- data/lib/pdk/cli/util.rb +32 -48
- data/lib/pdk/cli/validate.rb +98 -96
- data/lib/pdk/cli.rb +124 -120
- data/lib/pdk/config/ini_file.rb +4 -3
- data/lib/pdk/config/ini_file_setting.rb +6 -10
- data/lib/pdk/config/json.rb +1 -0
- data/lib/pdk/config/json_schema_namespace.rb +5 -10
- data/lib/pdk/config/json_schema_setting.rb +3 -5
- data/lib/pdk/config/json_with_schema.rb +2 -4
- data/lib/pdk/config/namespace.rb +22 -14
- data/lib/pdk/config/setting.rb +5 -6
- data/lib/pdk/config/task_schema.json +116 -0
- data/lib/pdk/config/validator.rb +4 -4
- data/lib/pdk/config/yaml.rb +3 -8
- data/lib/pdk/config/yaml_with_schema.rb +4 -12
- data/lib/pdk/config.rb +47 -51
- data/lib/pdk/context/control_repo.rb +3 -2
- data/lib/pdk/context/module.rb +2 -2
- data/lib/pdk/context/none.rb +2 -2
- data/lib/pdk/context.rb +4 -5
- data/lib/pdk/control_repo.rb +3 -4
- data/lib/pdk/generate/defined_type.rb +3 -3
- data/lib/pdk/generate/fact.rb +3 -2
- data/lib/pdk/generate/function.rb +5 -4
- data/lib/pdk/generate/module.rb +91 -106
- data/lib/pdk/generate/provider.rb +5 -4
- data/lib/pdk/generate/puppet_class.rb +3 -3
- data/lib/pdk/generate/puppet_object.rb +9 -12
- data/lib/pdk/generate/task.rb +11 -10
- data/lib/pdk/generate/transport.rb +8 -7
- data/lib/pdk/generate.rb +1 -1
- data/lib/pdk/logger.rb +3 -2
- data/lib/pdk/module/build.rb +34 -49
- data/lib/pdk/module/convert.rb +13 -22
- data/lib/pdk/module/metadata.rb +53 -61
- data/lib/pdk/module/release.rb +19 -25
- data/lib/pdk/module/update.rb +4 -13
- data/lib/pdk/module/update_manager.rb +18 -25
- data/lib/pdk/module.rb +1 -1
- data/lib/pdk/monkey_patches.rb +268 -0
- data/lib/pdk/report/event.rb +12 -37
- data/lib/pdk/report.rb +11 -7
- data/lib/pdk/template/fetcher/git.rb +7 -8
- data/lib/pdk/template/fetcher/local.rb +1 -0
- data/lib/pdk/template/fetcher.rb +4 -2
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +4 -9
- data/lib/pdk/template/renderer/v1/renderer.rb +19 -20
- data/lib/pdk/template/renderer/v1/template_file.rb +4 -8
- data/lib/pdk/template/renderer/v1.rb +1 -1
- data/lib/pdk/template/renderer.rb +1 -0
- data/lib/pdk/template/template_dir.rb +3 -3
- data/lib/pdk/template.rb +2 -6
- data/lib/pdk/tests/unit.rb +36 -25
- data/lib/pdk/util/bundler.rb +10 -14
- data/lib/pdk/util/changelog_generator.rb +15 -12
- data/lib/pdk/util/env.rb +1 -0
- data/lib/pdk/util/filesystem.rb +18 -17
- data/lib/pdk/util/git.rb +16 -21
- data/lib/pdk/util/json_finder.rb +7 -6
- data/lib/pdk/util/puppet_strings.rb +1 -1
- data/lib/pdk/util/puppet_version.rb +21 -68
- data/lib/pdk/util/ruby_version.rb +9 -13
- data/lib/pdk/util/template_uri.rb +17 -29
- data/lib/pdk/util/vendored_file.rb +5 -18
- data/lib/pdk/util/windows/api_types.rb +70 -64
- data/lib/pdk/util/windows/file.rb +31 -27
- data/lib/pdk/util/windows/process.rb +59 -61
- data/lib/pdk/util/windows/string.rb +19 -12
- data/lib/pdk/util.rb +13 -21
- data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +1 -1
- data/lib/pdk/validate/control_repo/environment_conf_validator.rb +25 -25
- data/lib/pdk/validate/external_command_validator.rb +6 -1
- data/lib/pdk/validate/internal_ruby_validator.rb +5 -4
- data/lib/pdk/validate/invokable_validator.rb +30 -20
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +12 -14
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +13 -15
- data/lib/pdk/validate/metadata/metadata_validator_group.rb +1 -1
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +16 -18
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +14 -14
- data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +1 -1
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +16 -18
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +1 -1
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +10 -11
- data/lib/pdk/validate/ruby/ruby_validator_group.rb +1 -1
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +19 -24
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +11 -13
- data/lib/pdk/validate/tasks/tasks_validator_group.rb +1 -1
- data/lib/pdk/validate/validator.rb +4 -2
- data/lib/pdk/validate/validator_group.rb +6 -3
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +27 -36
- data/lib/pdk/validate/yaml/yaml_validator_group.rb +1 -1
- data/lib/pdk/validate.rb +6 -6
- data/lib/pdk/version.rb +2 -2
- data/lib/pdk.rb +12 -12
- metadata +27 -35
- data/lib/pdk/cli/config/get.rb +0 -26
- data/lib/pdk/cli/config.rb +0 -22
- data/lib/pdk/cli/module/build.rb +0 -12
- data/lib/pdk/cli/module/generate.rb +0 -47
- data/lib/pdk/cli/module.rb +0 -14
data/lib/pdk/cli/console.rb
CHANGED
@@ -1,148 +1,150 @@
|
|
1
|
-
module PDK
|
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
|
-
# 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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
data/lib/pdk/cli/convert.rb
CHANGED
@@ -1,52 +1,50 @@
|
|
1
|
-
module PDK
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
29
|
-
|
17
|
+
run do |opts, _args, _cmd|
|
18
|
+
# Write the context information to the debug log
|
19
|
+
PDK.context.to_debug_log
|
30
20
|
|
31
|
-
|
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
|
-
|
23
|
+
raise PDK::CLI::ExitWithError, 'You can not specify --noop and --force when converting a module' if opts[:noop] && opts[:force]
|
36
24
|
|
37
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|
data/lib/pdk/cli/errors.rb
CHANGED
data/lib/pdk/cli/exec/command.rb
CHANGED
@@ -4,10 +4,8 @@ module PDK
|
|
4
4
|
module CLI
|
5
5
|
module Exec
|
6
6
|
class Command
|
7
|
-
attr_reader :argv
|
8
|
-
|
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
|
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
|
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
|
-
|
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
|
-
|
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}'"
|
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}"
|
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
|
-
|
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
|
-
|
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
|
-
|
271
|
+
# :nocov:
|
278
272
|
|
279
|
-
|
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
|
-
|
281
|
+
# :nocov:
|
288
282
|
end
|
289
283
|
end
|
290
284
|
end
|