pdk-akerl 1.9.1.1 → 1.14.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 +180 -0
- data/README.md +43 -4
- data/lib/pdk.rb +4 -2
- data/lib/pdk/analytics.rb +44 -0
- data/lib/pdk/analytics/client/google_analytics.rb +141 -0
- data/lib/pdk/analytics/client/noop.rb +23 -0
- data/lib/pdk/analytics/util.rb +17 -0
- data/lib/pdk/answer_file.rb +4 -1
- data/lib/pdk/cli.rb +50 -3
- data/lib/pdk/cli/build.rb +10 -4
- data/lib/pdk/cli/bundle.rb +10 -8
- data/lib/pdk/cli/config.rb +20 -0
- data/lib/pdk/cli/config/get.rb +24 -0
- data/lib/pdk/cli/console.rb +148 -0
- data/lib/pdk/cli/convert.rb +7 -2
- data/lib/pdk/cli/exec.rb +22 -190
- data/lib/pdk/cli/exec/command.rb +238 -0
- data/lib/pdk/cli/exec/interactive_command.rb +114 -0
- data/lib/pdk/cli/exec_group.rb +6 -6
- data/lib/pdk/cli/module/build.rb +0 -2
- data/lib/pdk/cli/module/generate.rb +4 -2
- data/lib/pdk/cli/new.rb +2 -0
- data/lib/pdk/cli/new/class.rb +2 -2
- data/lib/pdk/cli/new/defined_type.rb +4 -2
- data/lib/pdk/cli/new/module.rb +5 -0
- data/lib/pdk/cli/new/provider.rb +4 -2
- data/lib/pdk/cli/new/task.rb +4 -1
- data/lib/pdk/cli/new/test.rb +53 -0
- data/lib/pdk/cli/new/transport.rb +27 -0
- data/lib/pdk/cli/test.rb +0 -1
- data/lib/pdk/cli/test/unit.rb +18 -13
- data/lib/pdk/cli/update.rb +25 -3
- data/lib/pdk/cli/util.rb +111 -14
- data/lib/pdk/cli/util/interview.rb +10 -2
- data/lib/pdk/cli/util/option_validator.rb +4 -0
- data/lib/pdk/cli/util/spinner.rb +13 -0
- data/lib/pdk/cli/validate.rb +16 -5
- data/lib/pdk/config.rb +121 -0
- data/lib/pdk/config/analytics_schema.json +26 -0
- data/lib/pdk/config/errors.rb +5 -0
- data/lib/pdk/config/json.rb +34 -0
- data/lib/pdk/config/json_schema_namespace.rb +143 -0
- data/lib/pdk/config/json_schema_setting.rb +53 -0
- data/lib/pdk/config/json_with_schema.rb +50 -0
- data/lib/pdk/config/namespace.rb +332 -0
- data/lib/pdk/config/setting.rb +132 -0
- data/lib/pdk/config/yaml.rb +43 -0
- data/lib/pdk/config/yaml_with_schema.rb +59 -0
- data/lib/pdk/generate.rb +10 -3
- data/lib/pdk/generate/defined_type.rb +1 -0
- data/lib/pdk/generate/module.rb +62 -35
- data/lib/pdk/generate/provider.rb +0 -5
- data/lib/pdk/generate/puppet_class.rb +1 -0
- data/lib/pdk/generate/puppet_object.rb +88 -41
- data/lib/pdk/generate/transport.rb +87 -0
- data/lib/pdk/logger.rb +21 -1
- data/lib/pdk/module.rb +2 -2
- data/lib/pdk/module/build.rb +103 -10
- data/lib/pdk/module/convert.rb +85 -19
- data/lib/pdk/module/metadata.rb +17 -12
- data/lib/pdk/module/templatedir.rb +108 -40
- data/lib/pdk/module/update.rb +27 -15
- data/lib/pdk/module/update_manager.rb +23 -15
- data/lib/pdk/report.rb +4 -3
- data/lib/pdk/report/event.rb +8 -6
- data/lib/pdk/template_file.rb +1 -1
- data/lib/pdk/tests/unit.rb +48 -21
- data/lib/pdk/util.rb +29 -63
- data/lib/pdk/util/bundler.rb +19 -15
- data/lib/pdk/util/filesystem.rb +64 -1
- data/lib/pdk/util/git.rb +52 -1
- data/lib/pdk/util/puppet_strings.rb +123 -0
- data/lib/pdk/util/puppet_version.rb +27 -12
- data/lib/pdk/util/ruby_version.rb +30 -7
- data/lib/pdk/util/template_uri.rb +281 -0
- data/lib/pdk/util/vendored_file.rb +28 -24
- data/lib/pdk/util/version.rb +7 -8
- data/lib/pdk/util/windows.rb +1 -0
- data/lib/pdk/util/windows/api_types.rb +0 -7
- data/lib/pdk/util/windows/file.rb +1 -1
- data/lib/pdk/util/windows/string.rb +1 -1
- data/lib/pdk/validate/base_validator.rb +12 -14
- data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -4
- data/lib/pdk/validate/metadata/metadata_syntax.rb +5 -3
- data/lib/pdk/validate/metadata_validator.rb +0 -2
- data/lib/pdk/validate/puppet/puppet_epp.rb +137 -0
- data/lib/pdk/validate/puppet/puppet_lint.rb +0 -3
- data/lib/pdk/validate/puppet/puppet_syntax.rb +5 -5
- data/lib/pdk/validate/puppet_validator.rb +2 -3
- data/lib/pdk/validate/ruby/rubocop.rb +1 -6
- data/lib/pdk/validate/ruby_validator.rb +0 -2
- data/lib/pdk/validate/tasks/metadata_lint.rb +9 -5
- data/lib/pdk/validate/tasks/name.rb +5 -3
- data/lib/pdk/validate/tasks_validator.rb +0 -2
- data/lib/pdk/validate/yaml/syntax.rb +6 -4
- data/lib/pdk/validate/yaml_validator.rb +0 -2
- data/lib/pdk/version.rb +1 -1
- data/locales/pdk.pot +634 -307
- metadata +100 -45
@@ -0,0 +1,23 @@
|
|
1
|
+
module PDK
|
2
|
+
module Analytics
|
3
|
+
module Client
|
4
|
+
class Noop
|
5
|
+
attr_reader :logger
|
6
|
+
|
7
|
+
def initialize(opts)
|
8
|
+
@logger = opts[:logger]
|
9
|
+
end
|
10
|
+
|
11
|
+
def screen_view(screen, **_kwargs)
|
12
|
+
logger.debug "Skipping submission of '#{screen}' screenview because analytics is disabled"
|
13
|
+
end
|
14
|
+
|
15
|
+
def event(category, action, **_kwargs)
|
16
|
+
logger.debug "Skipping submission of '#{category} #{action}' event because analytics is disabled"
|
17
|
+
end
|
18
|
+
|
19
|
+
def finish; end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PDK
|
2
|
+
module Analytics
|
3
|
+
module Util
|
4
|
+
def self.fetch_os_async
|
5
|
+
require 'concurrent/configuration'
|
6
|
+
require 'concurrent/future'
|
7
|
+
|
8
|
+
Concurrent::Future.execute(executor: :io) do
|
9
|
+
require 'facter'
|
10
|
+
os = Facter.value('os')
|
11
|
+
|
12
|
+
os.nil? ? 'unknown' : "#{os['name']} #{os.fetch('release', {}).fetch('major', '')}".strip
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/pdk/answer_file.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'json'
|
2
1
|
require 'pdk/util/filesystem'
|
3
2
|
|
4
3
|
module PDK
|
@@ -80,6 +79,8 @@ module PDK
|
|
80
79
|
#
|
81
80
|
# @return [Hash{String => Object}] The existing questions and answers.
|
82
81
|
def read_from_disk
|
82
|
+
require 'json'
|
83
|
+
|
83
84
|
return {} if !File.file?(answer_file_path) || File.zero?(answer_file_path)
|
84
85
|
|
85
86
|
unless File.readable?(answer_file_path)
|
@@ -108,6 +109,8 @@ module PDK
|
|
108
109
|
#
|
109
110
|
# @raise [PDK::CLI::FatalError] if the answer file can not be written to.
|
110
111
|
def save_to_disk
|
112
|
+
require 'json'
|
113
|
+
|
111
114
|
FileUtils.mkdir_p(File.dirname(answer_file_path))
|
112
115
|
|
113
116
|
write_file(answer_file_path, JSON.pretty_generate(answers))
|
data/lib/pdk/cli.rb
CHANGED
@@ -1,20 +1,58 @@
|
|
1
1
|
require 'cri'
|
2
2
|
|
3
|
+
require 'pdk/analytics'
|
3
4
|
require 'pdk/cli/errors'
|
4
5
|
require 'pdk/cli/util'
|
5
6
|
require 'pdk/cli/util/command_redirector'
|
6
7
|
require 'pdk/cli/util/option_normalizer'
|
7
8
|
require 'pdk/cli/util/option_validator'
|
8
|
-
require 'pdk/
|
9
|
-
require 'pdk/generate/module'
|
9
|
+
require 'pdk/config'
|
10
10
|
require 'pdk/i18n'
|
11
11
|
require 'pdk/logger'
|
12
12
|
require 'pdk/report'
|
13
13
|
require 'pdk/util/version'
|
14
14
|
require 'pdk/util/puppet_version'
|
15
|
+
require 'pdk/util/filesystem'
|
16
|
+
|
17
|
+
class Cri::Command::CriExitException
|
18
|
+
def initialize(is_error:)
|
19
|
+
@is_error = is_error
|
20
|
+
PDK.analytics.event('CLI', 'invalid command', label: PDK::CLI.anonymised_args.join(' ')) if error?
|
21
|
+
end
|
22
|
+
end
|
15
23
|
|
16
24
|
module PDK::CLI
|
25
|
+
# Attempt to anonymise the raw ARGV array if the command parsing failed.
|
26
|
+
#
|
27
|
+
# If an item does not start with '-' but is preceeded by an item that does
|
28
|
+
# start with '-', assume that these items are an option/value pair and redact
|
29
|
+
# the value. Any additional values that do not start with '-' that follow an
|
30
|
+
# option/value pair are assumed to be arguments (rather than subcommand
|
31
|
+
# names) and are also redacted.
|
32
|
+
#
|
33
|
+
# @example
|
34
|
+
# # Where PDK::CLI.args => ['new', 'plan', '--some', 'value', 'plan_name']
|
35
|
+
#
|
36
|
+
# PDK::CLI.anonymised_args
|
37
|
+
# => ['new', 'plan', '--some', 'redacted', 'redacted']
|
38
|
+
#
|
39
|
+
# @return Array[String] the command arguments with any identifying values
|
40
|
+
# redacted.
|
41
|
+
def self.anonymised_args
|
42
|
+
in_args = false
|
43
|
+
@args.map do |arg|
|
44
|
+
if arg.start_with?('-')
|
45
|
+
in_args = true
|
46
|
+
arg
|
47
|
+
else
|
48
|
+
in_args ? 'redacted' : arg
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
17
53
|
def self.run(args)
|
54
|
+
@args = args
|
55
|
+
PDK::Config.analytics_config_interview! unless ENV['PDK_DISABLE_ANALYTICS'] || PDK::Config.analytics_config_exist?
|
18
56
|
@base_cmd.run(args)
|
19
57
|
rescue PDK::CLI::ExitWithError => e
|
20
58
|
PDK.logger.send(e.log_level, e.message)
|
@@ -39,11 +77,17 @@ module PDK::CLI
|
|
39
77
|
end
|
40
78
|
|
41
79
|
def self.template_url_option(dsl)
|
42
|
-
|
80
|
+
require 'pdk/util/template_uri'
|
81
|
+
|
82
|
+
desc = _('Specifies the URL to the template to use when creating new modules or classes. (default: %{default_url})') % { default_url: PDK::Util::TemplateURI.default_template_uri }
|
43
83
|
|
44
84
|
dsl.option nil, 'template-url', desc, argument: :required
|
45
85
|
end
|
46
86
|
|
87
|
+
def self.template_ref_option(dsl)
|
88
|
+
dsl.option nil, 'template-ref', _('Specifies the template git branch or tag to use when creating new modules or classes.'), argument: :required
|
89
|
+
end
|
90
|
+
|
47
91
|
def self.skip_interview_option(dsl)
|
48
92
|
dsl.option nil, 'skip-interview', _('When specified, skips interactive querying of metadata.')
|
49
93
|
end
|
@@ -96,18 +140,21 @@ module PDK::CLI
|
|
96
140
|
end
|
97
141
|
|
98
142
|
option nil, 'answer-file', _('Path to an answer file.'), argument: :required, hidden: true do |value|
|
143
|
+
require 'pdk/answer_file'
|
99
144
|
PDK.answer_file = value
|
100
145
|
end
|
101
146
|
end
|
102
147
|
|
103
148
|
require 'pdk/cli/bundle'
|
104
149
|
require 'pdk/cli/build'
|
150
|
+
require 'pdk/cli/config'
|
105
151
|
require 'pdk/cli/convert'
|
106
152
|
require 'pdk/cli/new'
|
107
153
|
require 'pdk/cli/test'
|
108
154
|
require 'pdk/cli/update'
|
109
155
|
require 'pdk/cli/validate'
|
110
156
|
require 'pdk/cli/module'
|
157
|
+
require 'pdk/cli/console'
|
111
158
|
|
112
159
|
@base_cmd.add_command Cri::Command.new_basic_help
|
113
160
|
end
|
data/lib/pdk/cli/build.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'pdk/cli/util'
|
2
|
-
|
3
1
|
module PDK::CLI
|
4
2
|
@build_cmd = @base_cmd.define_command do
|
5
3
|
name 'build'
|
@@ -14,6 +12,8 @@ module PDK::CLI
|
|
14
12
|
|
15
13
|
run do |opts, _args, _cmd|
|
16
14
|
require 'pdk/module/build'
|
15
|
+
require 'pdk/module/metadata'
|
16
|
+
require 'pdk/cli/util'
|
17
17
|
|
18
18
|
# Make sure build is being run in a valid module directory with a metadata.json
|
19
19
|
PDK::CLI::Util.ensure_in_module!(
|
@@ -21,6 +21,8 @@ module PDK::CLI
|
|
21
21
|
log_level: :info,
|
22
22
|
)
|
23
23
|
|
24
|
+
PDK::CLI::Util.analytics_screen_view('build', opts)
|
25
|
+
|
24
26
|
module_metadata = PDK::Module::Metadata.from_file('metadata.json')
|
25
27
|
|
26
28
|
# TODO: Ensure forge metadata has been set, or call out to interview
|
@@ -28,8 +30,12 @@ module PDK::CLI
|
|
28
30
|
#
|
29
31
|
unless module_metadata.forge_ready?
|
30
32
|
if opts[:force]
|
31
|
-
PDK.logger.
|
32
|
-
|
33
|
+
PDK.logger.warn _(
|
34
|
+
'This module is missing the following fields in the metadata.json: %{fields}. ' \
|
35
|
+
'These missing fields may affect the visibility of the module on the Forge.',
|
36
|
+
) % {
|
37
|
+
fields: module_metadata.missing_fields.join(', '),
|
38
|
+
}
|
33
39
|
else
|
34
40
|
module_metadata.interview_for_forge!
|
35
41
|
module_metadata.write!('metadata.json')
|
data/lib/pdk/cli/bundle.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module PDK::CLI
|
3
2
|
@bundle_cmd = @base_cmd.define_command do
|
4
3
|
name 'bundle'
|
@@ -7,35 +6,38 @@ module PDK::CLI
|
|
7
6
|
description _(<<-EOF
|
8
7
|
[experimental] For advanced users, pdk bundle runs arbitrary commands in the bundler environment that pdk manages.
|
9
8
|
Careless use of this command can lead to errors that pdk can't help recover from.
|
10
|
-
|
11
|
-
Note that for PowerShell the '--' needs to be escaped using a backtick: '`--' to avoid it being parsed by the shell.
|
12
9
|
EOF
|
13
10
|
)
|
14
11
|
skip_option_parsing
|
15
12
|
|
16
13
|
run do |_opts, args, _cmd|
|
14
|
+
require 'pdk/cli/exec/interactive_command'
|
15
|
+
require 'pdk/util/bundler'
|
16
|
+
|
17
17
|
PDK::CLI::Util.ensure_in_module!(
|
18
18
|
message: _('`pdk bundle` can only be run from inside a valid module directory.'),
|
19
19
|
)
|
20
20
|
|
21
21
|
PDK::CLI::Util.validate_puppet_version_opts({})
|
22
22
|
|
23
|
-
|
23
|
+
PDK::CLI::Util.analytics_screen_view('bundle')
|
24
|
+
|
25
|
+
# Ensure that the correct Ruby is activated before running command.
|
24
26
|
puppet_env = PDK::CLI::Util.puppet_from_opts_or_env({})
|
25
27
|
PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
|
26
28
|
|
27
29
|
gemfile_env = PDK::Util::Bundler::BundleHelper.gemfile_env(puppet_env[:gemset])
|
28
30
|
|
29
|
-
|
31
|
+
require 'pdk/cli/exec'
|
32
|
+
require 'pdk/cli/exec/interactive_command'
|
33
|
+
|
34
|
+
command = PDK::CLI::Exec::InteractiveCommand.new(PDK::CLI::Exec.bundle_bin, *args).tap do |c|
|
30
35
|
c.context = :pwd
|
31
36
|
c.update_environment(gemfile_env)
|
32
37
|
end
|
33
38
|
|
34
39
|
result = command.execute!
|
35
40
|
|
36
|
-
$stderr.puts result[:stdout]
|
37
|
-
$stderr.puts result[:stderr]
|
38
|
-
|
39
41
|
exit result[:exit_code]
|
40
42
|
end
|
41
43
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module PDK::CLI
|
2
|
+
@config_cmd = @base_cmd.define_command do
|
3
|
+
name 'config'
|
4
|
+
usage _('config [subcommand] [options]')
|
5
|
+
summary _('Configure the Puppet Development Kit.')
|
6
|
+
default_subcommand 'help'
|
7
|
+
|
8
|
+
run do |_opts, args, _cmd|
|
9
|
+
if args == ['help']
|
10
|
+
PDK::CLI.run(%w[config --help])
|
11
|
+
exit 0
|
12
|
+
end
|
13
|
+
|
14
|
+
PDK::CLI.run(%w[config help]) if args.empty?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
@config_cmd.add_command Cri::Command.new_basic_help
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'pdk/cli/config/get'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module PDK::CLI
|
2
|
+
@config_get_cmd = @config_cmd.define_command do
|
3
|
+
name 'get'
|
4
|
+
usage _('config get [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
|
@@ -0,0 +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
|
+
Dir.exist?(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
|