pdk 2.4.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +803 -1329
- data/LICENSE +201 -201
- data/README.md +165 -163
- data/exe/pdk +10 -10
- data/lib/pdk/analytics/client/google_analytics.rb +143 -143
- data/lib/pdk/analytics/client/noop.rb +25 -25
- data/lib/pdk/analytics/util.rb +19 -19
- data/lib/pdk/analytics.rb +30 -30
- data/lib/pdk/answer_file.rb +12 -12
- data/lib/pdk/bolt.rb +19 -19
- data/lib/pdk/cli/build.rb +82 -82
- data/lib/pdk/cli/bundle.rb +48 -48
- data/lib/pdk/cli/config/get.rb +26 -26
- data/lib/pdk/cli/config.rb +22 -22
- data/lib/pdk/cli/console.rb +148 -148
- data/lib/pdk/cli/convert.rb +52 -52
- data/lib/pdk/cli/env.rb +52 -52
- data/lib/pdk/cli/errors.rb +25 -25
- data/lib/pdk/cli/exec/command.rb +293 -293
- data/lib/pdk/cli/exec/interactive_command.rb +114 -114
- data/lib/pdk/cli/exec.rb +84 -84
- data/lib/pdk/cli/exec_group.rb +104 -104
- data/lib/pdk/cli/get/config.rb +24 -24
- data/lib/pdk/cli/get.rb +20 -20
- data/lib/pdk/cli/module/build.rb +12 -12
- data/lib/pdk/cli/module/generate.rb +47 -47
- data/lib/pdk/cli/module.rb +14 -14
- data/lib/pdk/cli/new/class.rb +32 -32
- data/lib/pdk/cli/new/defined_type.rb +32 -32
- data/lib/pdk/cli/new/fact.rb +29 -29
- data/lib/pdk/cli/new/function.rb +29 -29
- data/lib/pdk/cli/new/module.rb +53 -53
- data/lib/pdk/cli/new/provider.rb +29 -29
- data/lib/pdk/cli/new/task.rb +34 -34
- data/lib/pdk/cli/new/test.rb +52 -52
- data/lib/pdk/cli/new/transport.rb +27 -27
- data/lib/pdk/cli/new.rb +21 -21
- data/lib/pdk/cli/release/prep.rb +39 -39
- data/lib/pdk/cli/release/publish.rb +50 -50
- data/lib/pdk/cli/release.rb +194 -194
- data/lib/pdk/cli/remove/config.rb +80 -80
- data/lib/pdk/cli/remove.rb +20 -20
- data/lib/pdk/cli/set/config.rb +119 -119
- data/lib/pdk/cli/set.rb +20 -20
- data/lib/pdk/cli/test/unit.rb +90 -90
- data/lib/pdk/cli/test.rb +11 -11
- data/lib/pdk/cli/update.rb +64 -64
- data/lib/pdk/cli/util/command_redirector.rb +27 -27
- data/lib/pdk/cli/util/interview.rb +72 -72
- data/lib/pdk/cli/util/option_normalizer.rb +55 -55
- data/lib/pdk/cli/util/option_validator.rb +68 -68
- data/lib/pdk/cli/util/spinner.rb +13 -13
- data/lib/pdk/cli/util/update_manager_printer.rb +82 -82
- data/lib/pdk/cli/util.rb +305 -305
- data/lib/pdk/cli/validate.rb +116 -116
- data/lib/pdk/cli.rb +175 -175
- data/lib/pdk/config/analytics_schema.json +26 -26
- data/lib/pdk/config/errors.rb +5 -5
- data/lib/pdk/config/ini_file.rb +183 -183
- data/lib/pdk/config/ini_file_setting.rb +39 -39
- data/lib/pdk/config/json.rb +34 -34
- data/lib/pdk/config/json_schema_namespace.rb +142 -142
- data/lib/pdk/config/json_schema_setting.rb +53 -53
- data/lib/pdk/config/json_with_schema.rb +49 -49
- data/lib/pdk/config/namespace.rb +354 -354
- data/lib/pdk/config/setting.rb +135 -135
- data/lib/pdk/config/validator.rb +31 -31
- data/lib/pdk/config/yaml.rb +46 -46
- data/lib/pdk/config/yaml_with_schema.rb +59 -59
- data/lib/pdk/config.rb +390 -390
- data/lib/pdk/context/control_repo.rb +60 -60
- data/lib/pdk/context/module.rb +28 -28
- data/lib/pdk/context/none.rb +22 -22
- data/lib/pdk/context.rb +99 -99
- data/lib/pdk/control_repo.rb +90 -90
- data/lib/pdk/generate/defined_type.rb +43 -43
- data/lib/pdk/generate/fact.rb +25 -25
- data/lib/pdk/generate/function.rb +48 -48
- data/lib/pdk/generate/module.rb +352 -352
- data/lib/pdk/generate/provider.rb +28 -28
- data/lib/pdk/generate/puppet_class.rb +43 -43
- data/lib/pdk/generate/puppet_object.rb +232 -232
- data/lib/pdk/generate/task.rb +68 -68
- data/lib/pdk/generate/transport.rb +33 -33
- data/lib/pdk/generate.rb +24 -24
- data/lib/pdk/i18n.rb +4 -4
- data/lib/pdk/logger.rb +45 -45
- data/lib/pdk/module/build.rb +322 -322
- data/lib/pdk/module/convert.rb +296 -296
- data/lib/pdk/module/metadata.rb +202 -202
- data/lib/pdk/module/release.rb +260 -260
- data/lib/pdk/module/update.rb +131 -131
- data/lib/pdk/module/update_manager.rb +227 -227
- data/lib/pdk/module.rb +30 -30
- data/lib/pdk/report/event.rb +370 -370
- data/lib/pdk/report.rb +121 -121
- data/lib/pdk/template/fetcher/git.rb +85 -85
- data/lib/pdk/template/fetcher/local.rb +28 -28
- data/lib/pdk/template/fetcher.rb +98 -98
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -116
- data/lib/pdk/template/renderer/v1/renderer.rb +132 -132
- data/lib/pdk/template/renderer/v1/template_file.rb +102 -102
- data/lib/pdk/template/renderer/v1.rb +25 -25
- data/lib/pdk/template/renderer.rb +96 -96
- data/lib/pdk/template/template_dir.rb +67 -67
- data/lib/pdk/template.rb +59 -59
- data/lib/pdk/tests/unit.rb +252 -252
- data/lib/pdk/util/bundler.rb +259 -259
- data/lib/pdk/util/changelog_generator.rb +137 -137
- data/lib/pdk/util/env.rb +47 -47
- data/lib/pdk/util/filesystem.rb +138 -138
- data/lib/pdk/util/git.rb +179 -179
- data/lib/pdk/util/json_finder.rb +85 -85
- data/lib/pdk/util/puppet_strings.rb +125 -125
- data/lib/pdk/util/puppet_version.rb +266 -266
- data/lib/pdk/util/ruby_version.rb +179 -179
- data/lib/pdk/util/template_uri.rb +295 -295
- data/lib/pdk/util/vendored_file.rb +93 -93
- data/lib/pdk/util/version.rb +43 -43
- data/lib/pdk/util/windows/api_types.rb +82 -82
- data/lib/pdk/util/windows/file.rb +36 -36
- data/lib/pdk/util/windows/process.rb +79 -79
- data/lib/pdk/util/windows/string.rb +16 -16
- data/lib/pdk/util/windows.rb +15 -15
- data/lib/pdk/util.rb +278 -278
- data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -23
- data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -98
- data/lib/pdk/validate/external_command_validator.rb +208 -208
- data/lib/pdk/validate/internal_ruby_validator.rb +100 -100
- data/lib/pdk/validate/invokable_validator.rb +228 -228
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -86
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -78
- data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -20
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -133
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -66
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -137
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -21
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -80
- data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -19
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -88
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -50
- data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -20
- data/lib/pdk/validate/validator.rb +118 -118
- data/lib/pdk/validate/validator_group.rb +104 -104
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -95
- data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -19
- data/lib/pdk/validate.rb +94 -94
- data/lib/pdk/version.rb +4 -4
- data/lib/pdk.rb +76 -76
- data/locales/config.yaml +21 -21
- data/locales/pdk.pot +2111 -2094
- metadata +3 -3
data/lib/pdk/cli/console.rb
CHANGED
@@ -1,148 +1,148 @@
|
|
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
|
69
|
-
|
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
|
84
|
-
|
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
|
88
|
-
end
|
89
|
-
PDK.logger.warn _('Module fixtures not found, please run pdk bundle exec rake spec_prep.') unless existing_path
|
90
|
-
end
|
91
|
-
|
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
|
99
|
-
end
|
100
|
-
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
|
-
|
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 }
|
131
|
-
end
|
132
|
-
|
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)
|
137
|
-
end
|
138
|
-
command.execute!
|
139
|
-
end
|
140
|
-
|
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')}"
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
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
|
69
|
+
|
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
|
84
|
+
|
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
|
88
|
+
end
|
89
|
+
PDK.logger.warn _('Module fixtures not found, please run pdk bundle exec rake spec_prep.') unless existing_path
|
90
|
+
end
|
91
|
+
|
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
|
99
|
+
end
|
100
|
+
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
|
+
|
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 }
|
131
|
+
end
|
132
|
+
|
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)
|
137
|
+
end
|
138
|
+
command.execute!
|
139
|
+
end
|
140
|
+
|
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')}"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
data/lib/pdk/cli/convert.rb
CHANGED
@@ -1,52 +1,52 @@
|
|
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
|
23
|
-
|
24
|
-
if opts[:noop] && opts[:force]
|
25
|
-
raise PDK::CLI::ExitWithError, _('You can not specify --noop and --force when converting a module')
|
26
|
-
end
|
27
|
-
|
28
|
-
if opts[:'default-template']
|
29
|
-
raise PDK::CLI::ExitWithError, _('You can not specify --template-url and --default-template.') if opts[:'template-url']
|
30
|
-
|
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
|
34
|
-
|
35
|
-
PDK::CLI::Util.validate_template_opts(opts)
|
36
|
-
|
37
|
-
PDK::CLI::Util.analytics_screen_view('convert', opts)
|
38
|
-
|
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
|
43
|
-
|
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
|
48
|
-
|
49
|
-
PDK::Module::Convert.invoke(PDK.context.root_path, opts)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
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
|
23
|
+
|
24
|
+
if opts[:noop] && opts[:force]
|
25
|
+
raise PDK::CLI::ExitWithError, _('You can not specify --noop and --force when converting a module')
|
26
|
+
end
|
27
|
+
|
28
|
+
if opts[:'default-template']
|
29
|
+
raise PDK::CLI::ExitWithError, _('You can not specify --template-url and --default-template.') if opts[:'template-url']
|
30
|
+
|
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
|
34
|
+
|
35
|
+
PDK::CLI::Util.validate_template_opts(opts)
|
36
|
+
|
37
|
+
PDK::CLI::Util.analytics_screen_view('convert', opts)
|
38
|
+
|
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
|
43
|
+
|
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
|
48
|
+
|
49
|
+
PDK::Module::Convert.invoke(PDK.context.root_path, opts)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/pdk/cli/env.rb
CHANGED
@@ -1,52 +1,52 @@
|
|
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
|
-
|
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
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
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
|
+
|
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
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/pdk/cli/errors.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
require 'pdk'
|
2
|
-
|
3
|
-
module PDK
|
4
|
-
module CLI
|
5
|
-
class FatalError < StandardError
|
6
|
-
attr_reader :exit_code
|
7
|
-
|
8
|
-
def initialize(msg = _('An unexpected error has occurred. Try running the command again with --debug'), opts = {})
|
9
|
-
@exit_code = opts.fetch(:exit_code, 1)
|
10
|
-
super(msg)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class ExitWithError < StandardError
|
15
|
-
attr_reader :exit_code
|
16
|
-
attr_reader :log_level
|
17
|
-
|
18
|
-
def initialize(msg, opts = {})
|
19
|
-
@exit_code = opts.fetch(:exit_code, 1)
|
20
|
-
@log_level = opts.fetch(:log_level, :error)
|
21
|
-
super(msg)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
1
|
+
require 'pdk'
|
2
|
+
|
3
|
+
module PDK
|
4
|
+
module CLI
|
5
|
+
class FatalError < StandardError
|
6
|
+
attr_reader :exit_code
|
7
|
+
|
8
|
+
def initialize(msg = _('An unexpected error has occurred. Try running the command again with --debug'), opts = {})
|
9
|
+
@exit_code = opts.fetch(:exit_code, 1)
|
10
|
+
super(msg)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class ExitWithError < StandardError
|
15
|
+
attr_reader :exit_code
|
16
|
+
attr_reader :log_level
|
17
|
+
|
18
|
+
def initialize(msg, opts = {})
|
19
|
+
@exit_code = opts.fetch(:exit_code, 1)
|
20
|
+
@log_level = opts.fetch(:log_level, :error)
|
21
|
+
super(msg)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|