pdk 1.13.0 → 1.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +25 -0
- data/README.md +41 -0
- data/lib/pdk.rb +0 -13
- data/lib/pdk/analytics.rb +18 -2
- data/lib/pdk/analytics/client/google_analytics.rb +3 -0
- data/lib/pdk/answer_file.rb +4 -1
- data/lib/pdk/cli.rb +7 -2
- data/lib/pdk/cli/build.rb +2 -2
- data/lib/pdk/cli/bundle.rb +7 -1
- data/lib/pdk/cli/console.rb +148 -0
- data/lib/pdk/cli/convert.rb +2 -2
- data/lib/pdk/cli/exec.rb +14 -14
- data/lib/pdk/cli/exec/command.rb +16 -11
- data/lib/pdk/cli/exec/interactive_command.rb +4 -0
- data/lib/pdk/cli/exec_group.rb +5 -5
- data/lib/pdk/cli/module/build.rb +0 -2
- data/lib/pdk/cli/module/generate.rb +1 -2
- data/lib/pdk/cli/new.rb +1 -1
- data/lib/pdk/cli/new/defined_type.rb +2 -0
- data/lib/pdk/cli/new/provider.rb +2 -0
- data/lib/pdk/cli/new/task.rb +2 -0
- data/lib/pdk/cli/new/{unit_test.rb → test.rb} +16 -12
- data/lib/pdk/cli/new/transport.rb +2 -0
- data/lib/pdk/cli/test/unit.rb +5 -3
- data/lib/pdk/cli/update.rb +2 -3
- data/lib/pdk/cli/util.rb +45 -14
- data/lib/pdk/cli/util/spinner.rb +2 -2
- data/lib/pdk/cli/validate.rb +6 -2
- data/lib/pdk/config.rb +20 -8
- data/lib/pdk/config/analytics_schema.json +26 -0
- data/lib/pdk/config/json.rb +14 -3
- 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 +84 -76
- data/lib/pdk/config/setting.rb +132 -0
- data/lib/pdk/config/yaml.rb +15 -3
- data/lib/pdk/config/yaml_with_schema.rb +59 -0
- data/lib/pdk/generate.rb +0 -2
- data/lib/pdk/generate/module.rb +29 -16
- data/lib/pdk/generate/puppet_object.rb +31 -28
- data/lib/pdk/module.rb +2 -2
- data/lib/pdk/module/build.rb +21 -8
- data/lib/pdk/module/convert.rb +64 -7
- data/lib/pdk/module/metadata.rb +5 -1
- data/lib/pdk/module/templatedir.rb +24 -7
- data/lib/pdk/module/update.rb +5 -1
- data/lib/pdk/module/update_manager.rb +21 -13
- data/lib/pdk/report.rb +4 -3
- data/lib/pdk/report/event.rb +5 -3
- data/lib/pdk/tests/unit.rb +36 -7
- data/lib/pdk/util.rb +20 -8
- data/lib/pdk/util/bundler.rb +14 -6
- data/lib/pdk/util/filesystem.rb +5 -0
- data/lib/pdk/util/git.rb +6 -0
- data/lib/pdk/util/puppet_strings.rb +24 -2
- data/lib/pdk/util/puppet_version.rb +25 -10
- data/lib/pdk/util/ruby_version.rb +13 -1
- data/lib/pdk/util/template_uri.rb +23 -2
- data/lib/pdk/util/vendored_file.rb +28 -24
- data/lib/pdk/util/version.rb +5 -5
- data/lib/pdk/validate/base_validator.rb +5 -4
- 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 +4 -4
- data/lib/pdk/validate/puppet/puppet_lint.rb +0 -3
- data/lib/pdk/validate/puppet/puppet_syntax.rb +4 -4
- data/lib/pdk/validate/puppet_validator.rb +0 -2
- data/lib/pdk/validate/ruby/rubocop.rb +0 -5
- 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 +4 -2
- data/lib/pdk/validate/tasks_validator.rb +0 -2
- data/lib/pdk/validate/yaml/syntax.rb +4 -4
- data/lib/pdk/validate/yaml_validator.rb +0 -2
- data/lib/pdk/version.rb +1 -1
- data/locales/pdk.pot +351 -311
- metadata +11 -7
- data/lib/pdk/config/validator.rb +0 -31
- data/lib/pdk/config/value.rb +0 -94
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2b164195fde06a45412e475f2afc5916a45208da08c90841dd30b9b01808ca6f
|
4
|
+
data.tar.gz: e449e823329c01f0542da0c7a864e91019a9dad86054083c62f7f2bdf67488e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76b3ccf9f3b8d4ab51784f9690d44b0faf165af9a7b6df9ebee00d4a2c612050bf29a69b413163177d330ad2bf354a34437c9b870506c8e32a67d26e0d24e220
|
7
|
+
data.tar.gz: 78816fe4269f30053ac201c8eb8bb86be89cc0dc2440e4fa3c9c13312417621a843a8751b4b009ab33b699b835471f012ec18b5e7ba1723566301c1d8ada054e
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,31 @@ All changes to this repo will be documented in this file.
|
|
4
4
|
See the [release notes](https://puppet.com/docs/pdk/latest/release_notes.html) for a high-level summary.
|
5
5
|
|
6
6
|
|
7
|
+
## [v1.14.0](https://github.com/puppetlabs/pdk/tree/v1.14.0) (2019-10-09)
|
8
|
+
[Full Changelog](https://github.com/puppetlabs/pdk/compare/v1.13.0...v1.14.0)
|
9
|
+
|
10
|
+
**Implemented enhancements:**
|
11
|
+
|
12
|
+
- Add new "pdk console" command [\#758](https://github.com/puppetlabs/pdk/pull/758) ([logicminds](https://github.com/logicminds))
|
13
|
+
- \(PDK-1495\) Update pdk new test UX [\#749](https://github.com/puppetlabs/pdk/pull/749) ([rodjek](https://github.com/rodjek))
|
14
|
+
- \(PDK-680\) Make `pdk test unit` interactive by default [\#748](https://github.com/puppetlabs/pdk/pull/748) ([rodjek](https://github.com/rodjek))
|
15
|
+
- \(PDK-1047\) Add --add-tests to pdk convert [\#746](https://github.com/puppetlabs/pdk/pull/746) ([rodjek](https://github.com/rodjek))
|
16
|
+
|
17
|
+
**Merged pull requests:**
|
18
|
+
|
19
|
+
- \(fixup\) Fix Bundle CLI lazy load [\#767](https://github.com/puppetlabs/pdk/pull/767) ([glennsarti](https://github.com/glennsarti))
|
20
|
+
- \(fixup\) Missing require from lazy load PR [\#766](https://github.com/puppetlabs/pdk/pull/766) ([rodjek](https://github.com/rodjek))
|
21
|
+
- \(maint\) Loosen tests for puppet-dev [\#765](https://github.com/puppetlabs/pdk/pull/765) ([glennsarti](https://github.com/glennsarti))
|
22
|
+
- \(PDK-680\) Update package tests for interactive `pdk test unit` [\#756](https://github.com/puppetlabs/pdk/pull/756) ([rodjek](https://github.com/rodjek))
|
23
|
+
- \(maint\) - Add new utility method for fixtures dir [\#755](https://github.com/puppetlabs/pdk/pull/755) ([logicminds](https://github.com/logicminds))
|
24
|
+
- \(maint\) Lazy load dependencies [\#754](https://github.com/puppetlabs/pdk/pull/754) ([rodjek](https://github.com/rodjek))
|
25
|
+
- \(maint\) - Allow no output when reading puppet\_from\_opts [\#753](https://github.com/puppetlabs/pdk/pull/753) ([logicminds](https://github.com/logicminds))
|
26
|
+
- \(maint\) Refactors method to use block assignment [\#752](https://github.com/puppetlabs/pdk/pull/752) ([logicminds](https://github.com/logicminds))
|
27
|
+
- \(maint\) Add CODEOWNERS file [\#751](https://github.com/puppetlabs/pdk/pull/751) ([glennsarti](https://github.com/glennsarti))
|
28
|
+
- \(PDK-1367\) Deprecation warning for Puppet \< 5.0.0 [\#747](https://github.com/puppetlabs/pdk/pull/747) ([rodjek](https://github.com/rodjek))
|
29
|
+
- \(PDK-1112\) Create json schema to validate pdk config file [\#742](https://github.com/puppetlabs/pdk/pull/742) ([glennsarti](https://github.com/glennsarti))
|
30
|
+
- \(MAINT\) Bump version to 1.14.0.pre [\#741](https://github.com/puppetlabs/pdk/pull/741) ([scotje](https://github.com/scotje))
|
31
|
+
|
7
32
|
## [v1.13.0](https://github.com/puppetlabs/pdk/tree/v1.13.0) (2019-08-29)
|
8
33
|
[Full Changelog](https://github.com/puppetlabs/pdk/compare/v1.12.0...v1.13.0)
|
9
34
|
|
data/README.md
CHANGED
@@ -22,6 +22,7 @@ puppet-syntax | Checks for correct syntax in Puppet manifests, templates, and Hi
|
|
22
22
|
puppetlabs_spec_helper | Provides classes, methods, and Rake tasks to help with spec testing Puppet code.
|
23
23
|
rspec-puppet | Tests the behavior of Puppet when it compiles your manifests into a catalog of Puppet resources.
|
24
24
|
rspec-puppet-facts | Adds support for running rspec-puppet tests against the facts for your supported operating systems.
|
25
|
+
puppet-debugger | Provides a REPL based debugger console.
|
25
26
|
|
26
27
|
|
27
28
|
## Installation
|
@@ -105,6 +106,46 @@ This command runs all available unit tests.
|
|
105
106
|
|
106
107
|
## Experimental features
|
107
108
|
|
109
|
+
### `pdk console` command
|
110
|
+
The pdk console command executes a session of the puppet debugger when inside a module and allows for exploration of puppet code. See the official [puppet debugger site](https://www.puppet-debugger.com) for more info and the official docs [site here.](https://docs.puppet-debugger.com)
|
111
|
+
|
112
|
+
To use, execute `pdk console` from inside your module directory. You can also supply the `--puppet-version` or `--pe-version` or `--puppet-dev` to swap out the puppet version when using the console.
|
113
|
+
|
114
|
+
Example (from within a module):
|
115
|
+
|
116
|
+
* `pdk console --puppet-version=5`
|
117
|
+
* `pdk console --pe-version=2018.1`
|
118
|
+
|
119
|
+
The `pdk console` command will also pass through any puppet debugger arguments you wish to use.
|
120
|
+
|
121
|
+
Example:
|
122
|
+
|
123
|
+
* `pdk console --no-facterdb`
|
124
|
+
* `pdk console --play https://gist.github.com/logicminds/4f6bcfd723c92aad1f01f6a800319fa4`
|
125
|
+
* `pdk console -e "md5('sdfasdfasdf')" --run-once --quiet`
|
126
|
+
|
127
|
+
Use `pdk console -h` for a further explanation of pass through arguments.
|
128
|
+
|
129
|
+
If you receive the following error you do not have the puppet-debugger gem installed.
|
130
|
+
|
131
|
+
```
|
132
|
+
pdk console -h
|
133
|
+
Error: Unknown Puppet subcommand 'debugger'
|
134
|
+
See 'puppet help' for help on available puppet subcommands
|
135
|
+
```
|
136
|
+
|
137
|
+
To fix this you will need to add the following entry to your .sync.yml file and run pdk update:
|
138
|
+
|
139
|
+
```
|
140
|
+
Gemfile:
|
141
|
+
required:
|
142
|
+
":development":
|
143
|
+
- gem: puppet-debugger
|
144
|
+
version: "~> 0.14"
|
145
|
+
```
|
146
|
+
|
147
|
+
**NOTE**: The puppet-debugger gem has been added to the [puppet-module-* gems](https://github.com/puppetlabs/puppet-module-gems/pull/117), so once you get the gem update you no longer need the .sync.yml entry.
|
148
|
+
|
108
149
|
### `pdk bundle` command
|
109
150
|
|
110
151
|
This command executes arbitrary commands in a bundler context within the module you're currently working on. Arguments to this command are passed straight through to bundler. This command is experimental and can lead to errors that can't be resolved by PDK itself.
|
data/lib/pdk.rb
CHANGED
@@ -5,21 +5,8 @@ require 'pdk/generate'
|
|
5
5
|
require 'pdk/i18n'
|
6
6
|
require 'pdk/logger'
|
7
7
|
require 'pdk/report'
|
8
|
-
require 'pdk/template_file'
|
9
8
|
require 'pdk/validate'
|
10
9
|
require 'pdk/version'
|
11
10
|
|
12
11
|
module PDK
|
13
|
-
def self.analytics
|
14
|
-
@analytics ||= PDK::Analytics.build_client(
|
15
|
-
logger: PDK.logger,
|
16
|
-
disabled: ENV['PDK_DISABLE_ANALYTICS'] || PDK.config.user['analytics']['disabled'],
|
17
|
-
user_id: PDK.config.user['analytics']['user-id'],
|
18
|
-
app_id: "UA-139917834-#{PDK::Util.development_mode? ? '2' : '1'}",
|
19
|
-
client: :google_analytics,
|
20
|
-
app_name: 'pdk',
|
21
|
-
app_version: PDK::VERSION,
|
22
|
-
app_installer: PDK::Util.package_install? ? 'package' : 'gem',
|
23
|
-
)
|
24
|
-
end
|
25
12
|
end
|
data/lib/pdk/analytics.rb
CHANGED
@@ -1,9 +1,25 @@
|
|
1
|
-
require 'securerandom'
|
2
|
-
require 'pdk/analytics/util'
|
3
1
|
require 'pdk/analytics/client/google_analytics'
|
4
2
|
require 'pdk/analytics/client/noop'
|
5
3
|
|
6
4
|
module PDK
|
5
|
+
def self.analytics
|
6
|
+
require 'pdk/config'
|
7
|
+
require 'pdk/logger'
|
8
|
+
require 'pdk/util'
|
9
|
+
require 'pdk/version'
|
10
|
+
|
11
|
+
@analytics ||= PDK::Analytics.build_client(
|
12
|
+
logger: PDK.logger,
|
13
|
+
disabled: ENV['PDK_DISABLE_ANALYTICS'] || PDK.config.user['analytics']['disabled'],
|
14
|
+
user_id: PDK.config.user['analytics']['user-id'],
|
15
|
+
app_id: "UA-139917834-#{PDK::Util.development_mode? ? '2' : '1'}",
|
16
|
+
client: :google_analytics,
|
17
|
+
app_name: 'pdk',
|
18
|
+
app_version: PDK::VERSION,
|
19
|
+
app_installer: PDK::Util.package_install? ? 'package' : 'gem',
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
7
23
|
module Analytics
|
8
24
|
CLIENTS = {
|
9
25
|
noop: Client::Noop,
|
@@ -25,6 +25,7 @@ module PDK
|
|
25
25
|
require 'concurrent/future'
|
26
26
|
require 'httpclient'
|
27
27
|
require 'locale'
|
28
|
+
require 'pdk/analytics/util'
|
28
29
|
|
29
30
|
@http = HTTPClient.new
|
30
31
|
@user_id = opts[:user_id]
|
@@ -78,6 +79,8 @@ module PDK
|
|
78
79
|
# Handle analytics submission in the background to avoid blocking the
|
79
80
|
# app or polluting the log with errors
|
80
81
|
Concurrent::Future.execute(executor: @executor) do
|
82
|
+
require 'json'
|
83
|
+
|
81
84
|
logger.debug "Submitting analytics: #{JSON.pretty_generate(params)}"
|
82
85
|
@http.post(TRACKING_URL, params)
|
83
86
|
logger.debug 'Completed analytics submission'
|
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,17 +1,18 @@
|
|
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'
|
15
16
|
|
16
17
|
class Cri::Command::CriExitException
|
17
18
|
def initialize(is_error:)
|
@@ -76,6 +77,8 @@ module PDK::CLI
|
|
76
77
|
end
|
77
78
|
|
78
79
|
def self.template_url_option(dsl)
|
80
|
+
require 'pdk/util/template_uri'
|
81
|
+
|
79
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 }
|
80
83
|
|
81
84
|
dsl.option nil, 'template-url', desc, argument: :required
|
@@ -137,6 +140,7 @@ module PDK::CLI
|
|
137
140
|
end
|
138
141
|
|
139
142
|
option nil, 'answer-file', _('Path to an answer file.'), argument: :required, hidden: true do |value|
|
143
|
+
require 'pdk/answer_file'
|
140
144
|
PDK.answer_file = value
|
141
145
|
end
|
142
146
|
end
|
@@ -150,6 +154,7 @@ module PDK::CLI
|
|
150
154
|
require 'pdk/cli/update'
|
151
155
|
require 'pdk/cli/validate'
|
152
156
|
require 'pdk/cli/module'
|
157
|
+
require 'pdk/cli/console'
|
153
158
|
|
154
159
|
@base_cmd.add_command Cri::Command.new_basic_help
|
155
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!(
|
data/lib/pdk/cli/bundle.rb
CHANGED
@@ -11,6 +11,9 @@ EOF
|
|
11
11
|
skip_option_parsing
|
12
12
|
|
13
13
|
run do |_opts, args, _cmd|
|
14
|
+
require 'pdk/cli/exec/interactive_command'
|
15
|
+
require 'pdk/util/bundler'
|
16
|
+
|
14
17
|
PDK::CLI::Util.ensure_in_module!(
|
15
18
|
message: _('`pdk bundle` can only be run from inside a valid module directory.'),
|
16
19
|
)
|
@@ -19,12 +22,15 @@ EOF
|
|
19
22
|
|
20
23
|
PDK::CLI::Util.analytics_screen_view('bundle')
|
21
24
|
|
22
|
-
# Ensure that the correct Ruby is activated before running
|
25
|
+
# Ensure that the correct Ruby is activated before running command.
|
23
26
|
puppet_env = PDK::CLI::Util.puppet_from_opts_or_env({})
|
24
27
|
PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
|
25
28
|
|
26
29
|
gemfile_env = PDK::Util::Bundler::BundleHelper.gemfile_env(puppet_env[:gemset])
|
27
30
|
|
31
|
+
require 'pdk/cli/exec'
|
32
|
+
require 'pdk/cli/exec/interactive_command'
|
33
|
+
|
28
34
|
command = PDK::CLI::Exec::InteractiveCommand.new(PDK::CLI::Exec.bundle_bin, *args).tap do |c|
|
29
35
|
c.context = :pwd
|
30
36
|
c.update_environment(gemfile_env)
|
@@ -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
|
data/lib/pdk/cli/convert.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'pdk/cli/util'
|
2
|
-
|
3
1
|
module PDK::CLI
|
4
2
|
@convert_cmd = @base_cmd.define_command do
|
5
3
|
name 'convert'
|
@@ -12,9 +10,11 @@ module PDK::CLI
|
|
12
10
|
PDK::CLI.full_interview_option(self)
|
13
11
|
flag nil, :noop, _('Do not convert the module, just output what would be done.')
|
14
12
|
flag nil, :force, _('Convert the module automatically, with no prompts.')
|
13
|
+
flag nil, :'add-tests', _('Add any missing tests while converting the module.')
|
15
14
|
|
16
15
|
run do |opts, _args, _cmd|
|
17
16
|
require 'pdk/module/convert'
|
17
|
+
require 'pdk/cli/util'
|
18
18
|
|
19
19
|
PDK::CLI::Util.ensure_in_module!(
|
20
20
|
check_module_layout: true,
|
data/lib/pdk/cli/exec.rb
CHANGED
@@ -1,37 +1,33 @@
|
|
1
|
-
require 'bundler'
|
2
|
-
require 'childprocess'
|
3
|
-
require 'English'
|
4
|
-
require 'tempfile'
|
5
|
-
require 'tty-which'
|
6
|
-
|
7
|
-
require 'pdk/util'
|
8
|
-
require 'pdk/util/git'
|
9
|
-
require 'pdk/util/ruby_version'
|
10
|
-
require 'pdk/cli/util/spinner'
|
11
|
-
|
12
1
|
module PDK
|
13
2
|
module CLI
|
14
3
|
module Exec
|
15
|
-
require 'pdk/cli/exec/command'
|
16
|
-
require 'pdk/cli/exec/interactive_command'
|
17
|
-
|
18
4
|
def self.execute(*cmd)
|
5
|
+
require 'pdk/cli/exec/command'
|
6
|
+
|
19
7
|
Command.new(*cmd).execute!
|
20
8
|
end
|
21
9
|
|
22
10
|
def self.execute_with_env(env, *cmd)
|
11
|
+
require 'pdk/cli/exec/command'
|
12
|
+
|
23
13
|
Command.new(*cmd).tap { |c| c.environment = env }.execute!
|
24
14
|
end
|
25
15
|
|
26
16
|
def self.execute_interactive(*cmd)
|
17
|
+
require 'pdk/cli/exec/interactive_command'
|
18
|
+
|
27
19
|
InteractiveCommand.new(*cmd).execute!
|
28
20
|
end
|
29
21
|
|
30
22
|
def self.execute_interactive_with_env(env, *cmd)
|
23
|
+
require 'pdk/cli/exec/interactive_command'
|
24
|
+
|
31
25
|
InteractiveCommand.new(*cmd).tap { |c| c.environment = env }.execute!
|
32
26
|
end
|
33
27
|
|
34
28
|
def self.ensure_bin_present!(bin_path, bin_name)
|
29
|
+
require 'tty-which'
|
30
|
+
|
35
31
|
message = _('Unable to find `%{name}`. Check that it is installed and try again.') % {
|
36
32
|
name: bin_name,
|
37
33
|
}
|
@@ -46,6 +42,8 @@ module PDK
|
|
46
42
|
end
|
47
43
|
|
48
44
|
def self.bundle_bin
|
45
|
+
require 'pdk/util/ruby_version'
|
46
|
+
|
49
47
|
bundle_bin = Gem.win_platform? ? 'bundle.bat' : 'bundle'
|
50
48
|
vendored_bin_path = File.join('private', 'ruby', PDK::Util::RubyVersion.active_ruby_version, 'bin', bundle_bin)
|
51
49
|
|
@@ -53,6 +51,8 @@ module PDK
|
|
53
51
|
end
|
54
52
|
|
55
53
|
def self.try_vendored_bin(vendored_bin_path, fallback)
|
54
|
+
require 'pdk/util'
|
55
|
+
|
56
56
|
unless PDK::Util.package_install?
|
57
57
|
PDK.logger.debug(_("PDK package installation not found. Trying '%{fallback}' from the system PATH instead.") % {
|
58
58
|
fallback: fallback,
|