pdk 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +300 -21
- data/lib/pdk/cli.rb +3 -2
- data/lib/pdk/cli/bundle.rb +0 -2
- data/lib/pdk/cli/convert.rb +25 -0
- data/lib/pdk/cli/exec.rb +4 -34
- data/lib/pdk/cli/exec_group.rb +2 -2
- data/lib/pdk/cli/module.rb +2 -3
- data/lib/pdk/cli/module/generate.rb +9 -4
- data/lib/pdk/cli/new/class.rb +1 -1
- data/lib/pdk/cli/new/module.rb +12 -9
- data/lib/pdk/cli/test/unit.rb +16 -7
- data/lib/pdk/cli/util.rb +47 -4
- data/lib/pdk/generate.rb +4 -4
- data/lib/pdk/{generators → generate}/defined_type.rb +1 -1
- data/lib/pdk/{generators → generate}/module.rb +47 -58
- data/lib/pdk/{generators → generate}/puppet_class.rb +1 -1
- data/lib/pdk/{generators → generate}/puppet_object.rb +1 -1
- data/lib/pdk/{generators → generate}/task.rb +1 -1
- data/lib/pdk/module/convert.rb +163 -0
- data/lib/pdk/module/metadata.rb +11 -3
- data/lib/pdk/module/templatedir.rb +81 -42
- data/lib/pdk/module/update_manager.rb +203 -0
- data/lib/pdk/tests/unit.rb +7 -6
- data/lib/pdk/util.rb +42 -1
- data/lib/pdk/util/bundler.rb +2 -2
- data/lib/pdk/util/git.rb +36 -0
- data/lib/pdk/util/version.rb +2 -1
- data/lib/pdk/validate.rb +3 -3
- data/lib/pdk/{validators → validate}/base_validator.rb +0 -0
- data/lib/pdk/{validators → validate}/metadata/metadata_json_lint.rb +1 -1
- data/lib/pdk/{validators → validate}/metadata/metadata_syntax.rb +2 -2
- data/lib/pdk/{validators → validate}/metadata/task_metadata_lint.rb +3 -3
- data/lib/pdk/{validators → validate}/metadata_validator.rb +4 -4
- data/lib/pdk/{validators → validate}/puppet/puppet_lint.rb +1 -1
- data/lib/pdk/{validators → validate}/puppet/puppet_syntax.rb +1 -1
- data/lib/pdk/{validators → validate}/puppet_validator.rb +3 -3
- data/lib/pdk/{validators → validate}/ruby/rubocop.rb +2 -2
- data/lib/pdk/{validators → validate}/ruby_validator.rb +2 -2
- data/lib/pdk/version.rb +2 -1
- metadata +36 -18
data/lib/pdk/cli/bundle.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'pdk/cli/util'
|
2
|
+
|
3
|
+
module PDK::CLI
|
4
|
+
@convert_cmd = @base_cmd.define_command do
|
5
|
+
name 'convert'
|
6
|
+
usage _('convert [options]')
|
7
|
+
summary _('Convert an existing module to be compatible with the PDK.')
|
8
|
+
|
9
|
+
PDK::CLI.template_url_option(self)
|
10
|
+
PDK::CLI.skip_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
|
+
|
14
|
+
run do |opts, _args, _cmd|
|
15
|
+
require 'pdk/module/convert'
|
16
|
+
PDK::CLI::Util.ensure_in_module!(check_module_layout: true)
|
17
|
+
|
18
|
+
if opts[:noop] && opts[:force]
|
19
|
+
raise PDK::CLI::ExitWithError, _('You can not specify --noop and --force when converting a module')
|
20
|
+
end
|
21
|
+
|
22
|
+
PDK::Module::Convert.invoke(opts)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/pdk/cli/exec.rb
CHANGED
@@ -5,6 +5,7 @@ require 'tty-spinner'
|
|
5
5
|
require 'tty-which'
|
6
6
|
|
7
7
|
require 'pdk/util'
|
8
|
+
require 'pdk/util/git'
|
8
9
|
|
9
10
|
module PDK
|
10
11
|
module CLI
|
@@ -21,37 +22,6 @@ module PDK
|
|
21
22
|
raise PDK::CLI::FatalError, message unless TTY::Which.exist?(bin_path)
|
22
23
|
end
|
23
24
|
|
24
|
-
def self.git_bindir
|
25
|
-
@git_dir ||= File.join('private', 'git', Gem.win_platform? ? 'cmd' : 'bin')
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.git_paths
|
29
|
-
@paths ||= begin
|
30
|
-
paths = [File.join(PDK::Util.pdk_package_basedir, git_bindir)]
|
31
|
-
|
32
|
-
if Gem.win_platform?
|
33
|
-
paths << File.join(PDK::Util.pdk_package_basedir, 'private', 'git', 'mingw64', 'bin')
|
34
|
-
paths << File.join(PDK::Util.pdk_package_basedir, 'private', 'git', 'mingw64', 'libexec', 'git-core')
|
35
|
-
paths << File.join(PDK::Util.pdk_package_basedir, 'private', 'git', 'usr', 'bin')
|
36
|
-
end
|
37
|
-
|
38
|
-
paths
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.git_bin
|
43
|
-
git_bin = Gem.win_platform? ? 'git.exe' : 'git'
|
44
|
-
vendored_bin_path = File.join(git_bindir, git_bin)
|
45
|
-
|
46
|
-
try_vendored_bin(vendored_bin_path, git_bin)
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.git(*args)
|
50
|
-
ensure_bin_present!(git_bin, 'git')
|
51
|
-
|
52
|
-
execute(git_bin, *args)
|
53
|
-
end
|
54
|
-
|
55
25
|
def self.bundle(*args)
|
56
26
|
ensure_bin_present!(bundle_bin, 'bundler')
|
57
27
|
|
@@ -120,7 +90,7 @@ module PDK
|
|
120
90
|
end
|
121
91
|
|
122
92
|
def register_spinner(spinner, opts = {})
|
123
|
-
return
|
93
|
+
return unless PDK::CLI::Util.interactive?
|
124
94
|
@success_message = opts.delete(:success)
|
125
95
|
@failure_message = opts.delete(:failure)
|
126
96
|
|
@@ -128,7 +98,7 @@ module PDK
|
|
128
98
|
end
|
129
99
|
|
130
100
|
def add_spinner(message, opts = {})
|
131
|
-
return
|
101
|
+
return unless PDK::CLI::Util.interactive?
|
132
102
|
@success_message = opts.delete(:success)
|
133
103
|
@failure_message = opts.delete(:failure)
|
134
104
|
|
@@ -169,7 +139,7 @@ module PDK
|
|
169
139
|
File.join(@process.environment['GEM_PATH'], 'bin'),
|
170
140
|
package_binpath,
|
171
141
|
ENV['PATH'],
|
172
|
-
PDK::Util.package_install? ? PDK::
|
142
|
+
PDK::Util.package_install? ? PDK::Util::Git.git_paths : nil,
|
173
143
|
].compact.flatten.join(File::PATH_SEPARATOR)
|
174
144
|
|
175
145
|
mod_root = PDK::Util.module_root
|
data/lib/pdk/cli/exec_group.rb
CHANGED
@@ -11,7 +11,7 @@ module PDK
|
|
11
11
|
def initialize(message, opts = {})
|
12
12
|
@options = opts.merge(PDK::CLI::Util.spinner_opts_for_platform)
|
13
13
|
|
14
|
-
|
14
|
+
if PDK::CLI::Util.interactive?
|
15
15
|
@multi_spinner = TTY::Spinner::Multi.new("[:spinner] #{message}", @options)
|
16
16
|
@multi_spinner.auto_spin
|
17
17
|
end
|
@@ -31,7 +31,7 @@ module PDK
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def add_spinner(message, opts = {})
|
34
|
-
return
|
34
|
+
return unless PDK::CLI::Util.interactive?
|
35
35
|
@multi_spinner.register("[:spinner] #{message}", @options.merge(opts).merge(PDK::CLI::Util.spinner_opts_for_platform))
|
36
36
|
end
|
37
37
|
|
data/lib/pdk/cli/module.rb
CHANGED
@@ -2,10 +2,9 @@ module PDK::CLI
|
|
2
2
|
@module_cmd = @base_cmd.define_command do
|
3
3
|
name 'module'
|
4
4
|
usage _('module [options]')
|
5
|
-
summary _('
|
6
|
-
description _('
|
5
|
+
summary _('Provide CLI-backwards compatibility to the puppet module tool.')
|
6
|
+
description _('This command is only for reminding you how to accomplish tasks with the PDK, when you were previously doing them with the puppet module command.')
|
7
7
|
default_subcommand 'help'
|
8
|
-
be_hidden
|
9
8
|
end
|
10
9
|
|
11
10
|
@module_cmd.add_command Cri::Command.new_basic_help
|
@@ -5,13 +5,12 @@ module PDK::CLI
|
|
5
5
|
name 'generate'
|
6
6
|
usage _('generate [options] <module_name>')
|
7
7
|
summary _('This command is now \'pdk new module\'.')
|
8
|
-
be_hidden
|
9
8
|
|
10
9
|
PDK::CLI.template_url_option(self)
|
11
10
|
PDK::CLI.skip_interview_option(self)
|
12
11
|
|
13
12
|
run do |opts, args, _cmd|
|
14
|
-
require 'pdk/
|
13
|
+
require 'pdk/generate/module'
|
15
14
|
|
16
15
|
module_name = args[0]
|
17
16
|
|
@@ -27,8 +26,14 @@ module PDK::CLI
|
|
27
26
|
answer = redirect.run
|
28
27
|
|
29
28
|
if answer
|
30
|
-
|
31
|
-
|
29
|
+
module_name_parts = module_name.split('-', 2)
|
30
|
+
if module_name_parts.size > 1
|
31
|
+
opts[:username] = module_name_parts[0]
|
32
|
+
opts[:module_name] = module_name_parts[1]
|
33
|
+
else
|
34
|
+
opts[:module_name] = module_name
|
35
|
+
end
|
36
|
+
opts[:target_dir] = opts[:module_name]
|
32
37
|
|
33
38
|
PDK.logger.info(_('Creating new module: %{modname}') % { modname: module_name })
|
34
39
|
PDK::Generate::Module.invoke(opts)
|
data/lib/pdk/cli/new/class.rb
CHANGED
data/lib/pdk/cli/new/module.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module PDK::CLI
|
2
2
|
@new_module_cmd = @new_cmd.define_command do
|
3
3
|
name 'module'
|
4
|
-
usage _('module [options]
|
5
|
-
summary _('Create a new module named
|
4
|
+
usage _('module [options] [module_name] [target_dir]')
|
5
|
+
summary _('Create a new module named [module_name] using given options')
|
6
6
|
|
7
7
|
PDK::CLI.template_url_option(self)
|
8
8
|
PDK::CLI.skip_interview_option(self)
|
@@ -11,19 +11,22 @@ module PDK::CLI
|
|
11
11
|
"This should be a identifier from https://spdx.org/licenses/. Common values are 'Apache-2.0', 'MIT', or 'proprietary'."), argument: :required
|
12
12
|
|
13
13
|
run do |opts, args, _cmd|
|
14
|
-
require 'pdk/
|
14
|
+
require 'pdk/generate/module'
|
15
15
|
|
16
16
|
module_name = args[0]
|
17
17
|
target_dir = args[1]
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
unless module_name.nil? || module_name.empty?
|
20
|
+
module_name_parts = module_name.split('-', 2)
|
21
|
+
if module_name_parts.size > 1
|
22
|
+
opts[:username] = module_name_parts[0]
|
23
|
+
opts[:module_name] = module_name_parts[1]
|
24
|
+
else
|
25
|
+
opts[:module_name] = module_name
|
26
|
+
end
|
27
|
+
opts[:target_dir] = target_dir.nil? ? opts[:module_name] : target_dir
|
22
28
|
end
|
23
29
|
|
24
|
-
opts[:name] = module_name
|
25
|
-
opts[:target_dir] = target_dir.nil? ? module_name : target_dir
|
26
|
-
|
27
30
|
PDK.logger.info(_('Creating new module: %{modname}') % { modname: module_name })
|
28
31
|
PDK::Generate::Module.invoke(opts)
|
29
32
|
end
|
data/lib/pdk/cli/test/unit.rb
CHANGED
@@ -7,10 +7,11 @@ module PDK::CLI
|
|
7
7
|
usage _('unit [options]')
|
8
8
|
summary _('Run unit tests.')
|
9
9
|
|
10
|
-
flag nil, :list, _('
|
11
|
-
flag nil, :parallel, _('
|
10
|
+
flag nil, :list, _('List all available unit test files.')
|
11
|
+
flag nil, :parallel, _('Run unit tests in parallel.'), hidden: true
|
12
|
+
flag :v, :verbose, _('More verbose output. Displays examples in each unit test file.')
|
12
13
|
|
13
|
-
option nil, :tests, _('a comma-separated list of
|
14
|
+
option nil, :tests, _('Specify a comma-separated list of unit test files to run.'), argument: :required, default: '' do |values|
|
14
15
|
PDK::CLI::Util::OptionValidator.comma_separated_list?(values)
|
15
16
|
end
|
16
17
|
|
@@ -27,11 +28,19 @@ module PDK::CLI
|
|
27
28
|
if opts[:list]
|
28
29
|
examples = PDK::Test::Unit.list
|
29
30
|
if examples.empty?
|
30
|
-
puts _('No examples found.')
|
31
|
+
puts _('No unit test files with examples were found.')
|
31
32
|
else
|
32
|
-
puts _('
|
33
|
-
examples.
|
34
|
-
|
33
|
+
puts _('Unit Test Files:')
|
34
|
+
files = examples.map { |example| example[:file_path] }
|
35
|
+
files.uniq.each do |file|
|
36
|
+
puts _(file)
|
37
|
+
|
38
|
+
next unless opts[:verbose]
|
39
|
+
|
40
|
+
file_examples = examples.select { |example| example[:file_path] == file }
|
41
|
+
file_examples.each do |file_example|
|
42
|
+
puts _("\t%{id}\t%{description}" % { id: file_example[:id], description: file_example[:full_description] })
|
43
|
+
end
|
35
44
|
end
|
36
45
|
end
|
37
46
|
else
|
data/lib/pdk/cli/util.rb
CHANGED
@@ -1,13 +1,30 @@
|
|
1
1
|
module PDK
|
2
2
|
module CLI
|
3
3
|
module Util
|
4
|
+
MODULE_FOLDERS = %w[
|
5
|
+
manifests
|
6
|
+
lib
|
7
|
+
tasks
|
8
|
+
facts.d
|
9
|
+
functions
|
10
|
+
types
|
11
|
+
].freeze
|
12
|
+
|
4
13
|
# Ensures the calling code is being run from inside a module directory.
|
5
14
|
#
|
6
|
-
# @
|
7
|
-
#
|
8
|
-
|
15
|
+
# @param opts [Hash] options to change the behavior of the check logic.
|
16
|
+
# @option opts [Boolean] :check_module_layout Set to true to check for
|
17
|
+
# stardard module folder layout if the module does not contain
|
18
|
+
# a metadata.json file.
|
19
|
+
#
|
20
|
+
# @raise [PDK::CLI::ExitWithError] if the current directory does not
|
21
|
+
# contain a Puppet module.
|
22
|
+
def ensure_in_module!(opts = {})
|
23
|
+
return unless PDK::Util.module_root.nil?
|
24
|
+
return if opts[:check_module_layout] && PDK::CLI::Util::MODULE_FOLDERS.any? { |dir| File.directory?(dir) }
|
25
|
+
|
9
26
|
message = _('This command must be run from inside a valid module (no metadata.json found).')
|
10
|
-
raise PDK::CLI::ExitWithError, message
|
27
|
+
raise PDK::CLI::ExitWithError, message
|
11
28
|
end
|
12
29
|
module_function :ensure_in_module!
|
13
30
|
|
@@ -21,6 +38,32 @@ module PDK
|
|
21
38
|
{}
|
22
39
|
end
|
23
40
|
module_function :spinner_opts_for_platform
|
41
|
+
|
42
|
+
def prompt_for_yes(question_text, opts = {})
|
43
|
+
prompt = opts[:prompt] || TTY::Prompt.new(help_color: :cyan)
|
44
|
+
validator = proc { |value| [true, false].include?(value) || value =~ %r{\A(?:yes|y|no|n)\Z}i }
|
45
|
+
response = nil
|
46
|
+
|
47
|
+
begin
|
48
|
+
response = prompt.yes?(question_text) do |q|
|
49
|
+
q.validate(validator, _('Answer "Y" to continue or "n" to cancel.'))
|
50
|
+
end
|
51
|
+
rescue TTY::Prompt::Reader::InputInterrupt
|
52
|
+
PDK.logger.info opts[:cancel_message] if opts[:cancel_message]
|
53
|
+
end
|
54
|
+
|
55
|
+
response
|
56
|
+
end
|
57
|
+
module_function :prompt_for_yes
|
58
|
+
|
59
|
+
def interactive?
|
60
|
+
return false if PDK.logger.debug?
|
61
|
+
return !ENV['PDK_FRONTEND'].casecmp('noninteractive').zero? if ENV['PDK_FRONTEND']
|
62
|
+
return false unless $stderr.isatty
|
63
|
+
|
64
|
+
true
|
65
|
+
end
|
66
|
+
module_function :interactive?
|
24
67
|
end
|
25
68
|
end
|
26
69
|
end
|
data/lib/pdk/generate.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require 'pdk/
|
2
|
-
require 'pdk/
|
3
|
-
require 'pdk/
|
4
|
-
require 'pdk/
|
1
|
+
require 'pdk/generate/module'
|
2
|
+
require 'pdk/generate/defined_type'
|
3
|
+
require 'pdk/generate/puppet_class'
|
4
|
+
require 'pdk/generate/task'
|
5
5
|
require 'pdk/module/metadata'
|
6
6
|
require 'pdk/module/templatedir'
|
7
7
|
|
@@ -8,6 +8,7 @@ require 'pdk/logger'
|
|
8
8
|
require 'pdk/module/metadata'
|
9
9
|
require 'pdk/module/templatedir'
|
10
10
|
require 'pdk/cli/exec'
|
11
|
+
require 'pdk/cli/util'
|
11
12
|
require 'pdk/cli/util/interview'
|
12
13
|
require 'pdk/cli/util/option_validator'
|
13
14
|
require 'pdk/util'
|
@@ -16,40 +17,25 @@ require 'pdk/util/version'
|
|
16
17
|
module PDK
|
17
18
|
module Generate
|
18
19
|
class Module
|
19
|
-
def self.default_template_url
|
20
|
-
if !PDK.answers['template-url'].nil?
|
21
|
-
PDK.answers['template-url']
|
22
|
-
else
|
23
|
-
puppetlabs_template_url
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.puppetlabs_template_url
|
28
|
-
if PDK::Util.package_install?
|
29
|
-
'file://' + File.join(PDK::Util.package_cachedir, 'pdk-module-template.git')
|
30
|
-
else
|
31
|
-
'https://github.com/puppetlabs/pdk-module-template'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
20
|
def self.validate_options(opts)
|
36
|
-
unless PDK::CLI::Util::OptionValidator.valid_module_name?(opts[:
|
21
|
+
unless PDK::CLI::Util::OptionValidator.valid_module_name?(opts[:module_name])
|
37
22
|
error_msg = _(
|
38
23
|
"'%{module_name}' is not a valid module name.\n" \
|
39
24
|
'Module names must begin with a lowercase letter and can only include lowercase letters, digits, and underscores.',
|
40
|
-
) % { module_name: opts[:
|
25
|
+
) % { module_name: opts[:module_name] }
|
41
26
|
raise PDK::CLI::ExitWithError, error_msg
|
42
27
|
end
|
43
28
|
|
44
29
|
target_dir = File.expand_path(opts[:target_dir])
|
45
|
-
|
46
30
|
raise PDK::CLI::ExitWithError, _("The destination directory '%{dir}' already exists") % { dir: target_dir } if File.exist?(target_dir)
|
47
31
|
end
|
48
32
|
|
49
33
|
def self.invoke(opts = {})
|
50
|
-
validate_options(opts)
|
34
|
+
validate_options(opts) unless opts[:module_name].nil?
|
51
35
|
|
52
|
-
|
36
|
+
metadata = prepare_metadata(opts)
|
37
|
+
|
38
|
+
target_dir = File.expand_path(opts[:target_dir] || opts[:module_name])
|
53
39
|
parent_dir = File.dirname(target_dir)
|
54
40
|
|
55
41
|
begin
|
@@ -62,15 +48,13 @@ module PDK
|
|
62
48
|
}
|
63
49
|
end
|
64
50
|
|
65
|
-
metadata = prepare_metadata(opts)
|
66
|
-
|
67
51
|
temp_target_dir = PDK::Util.make_tmpdir_name('pdk-module-target')
|
68
52
|
|
69
53
|
prepare_module_directory(temp_target_dir)
|
70
54
|
|
71
|
-
template_url = opts.fetch(:'template-url', default_template_url)
|
55
|
+
template_url = opts.fetch(:'template-url', PDK::Util.default_template_url)
|
72
56
|
|
73
|
-
PDK::Module::TemplateDir.new(template_url, metadata.data) do |templates|
|
57
|
+
PDK::Module::TemplateDir.new(template_url, metadata.data, true) do |templates|
|
74
58
|
templates.render do |file_path, file_content|
|
75
59
|
file = Pathname.new(temp_target_dir) + file_path
|
76
60
|
file.dirname.mkpath
|
@@ -81,12 +65,10 @@ module PDK
|
|
81
65
|
# metadata (for a future update command).
|
82
66
|
metadata.update!(templates.metadata)
|
83
67
|
|
84
|
-
|
85
|
-
metadata_file.puts metadata.to_json
|
86
|
-
end
|
68
|
+
metadata.write!(File.join(temp_target_dir, 'metadata.json'))
|
87
69
|
end
|
88
70
|
|
89
|
-
if template_url == puppetlabs_template_url
|
71
|
+
if template_url == PDK::Util.puppetlabs_template_url
|
90
72
|
# If the user specifies our template via the command line, remove the
|
91
73
|
# saved template-url answer.
|
92
74
|
PDK.answers.update!('template-url' => nil) if opts.key?(:'template-url')
|
@@ -98,7 +80,7 @@ module PDK
|
|
98
80
|
|
99
81
|
begin
|
100
82
|
if FileUtils.mv(temp_target_dir, target_dir)
|
101
|
-
PDK.logger.info(_('Module \'%{name}\' generated at path \'%{path}\'.') % { name: opts[:
|
83
|
+
PDK.logger.info(_('Module \'%{name}\' generated at path \'%{path}\', from template \'%{template_url}\'.') % { name: opts[:module_name], path: target_dir, template_url: template_url })
|
102
84
|
PDK.logger.info(_('In your module directory, add classes with the \'pdk new class\' command.'))
|
103
85
|
end
|
104
86
|
rescue Errno::EACCES => e
|
@@ -112,7 +94,7 @@ module PDK
|
|
112
94
|
|
113
95
|
def self.username_from_login
|
114
96
|
login = Etc.getlogin || ''
|
115
|
-
login_clean = login.gsub(%r{[^0-9a-z]}i, '')
|
97
|
+
login_clean = login.downcase.gsub(%r{[^0-9a-z]}i, '')
|
116
98
|
login_clean = 'username' if login_clean.empty?
|
117
99
|
|
118
100
|
if login_clean != login
|
@@ -124,23 +106,23 @@ module PDK
|
|
124
106
|
login_clean
|
125
107
|
end
|
126
108
|
|
127
|
-
def self.prepare_metadata(opts)
|
128
|
-
username = PDK.answers['
|
109
|
+
def self.prepare_metadata(opts = {})
|
110
|
+
opts[:username] = (opts[:username] || PDK.answers['forge_username'] || username_from_login).downcase
|
129
111
|
|
130
112
|
defaults = {
|
131
|
-
'name' => "#{username}-#{opts[:name]}",
|
132
113
|
'version' => '0.1.0',
|
133
114
|
'dependencies' => [],
|
134
115
|
'requirements' => [
|
135
116
|
{ 'name' => 'puppet', 'version_requirement' => '>= 4.7.0 < 6.0.0' },
|
136
117
|
],
|
137
118
|
}
|
119
|
+
|
120
|
+
defaults['name'] = "#{opts[:username]}-#{opts[:module_name]}" unless opts[:module_name].nil?
|
138
121
|
defaults['author'] = PDK.answers['author'] unless PDK.answers['author'].nil?
|
139
122
|
defaults['license'] = PDK.answers['license'] unless PDK.answers['license'].nil?
|
140
123
|
defaults['license'] = opts[:license] if opts.key? :license
|
141
124
|
|
142
125
|
metadata = PDK::Module::Metadata.new(defaults)
|
143
|
-
|
144
126
|
module_interview(metadata, opts) unless opts[:'skip-interview']
|
145
127
|
|
146
128
|
metadata.update!('pdk-version' => PDK::Util::Version.version_string)
|
@@ -170,13 +152,21 @@ module PDK
|
|
170
152
|
def self.module_interview(metadata, opts = {})
|
171
153
|
questions = [
|
172
154
|
{
|
173
|
-
name: '
|
155
|
+
name: 'module_name',
|
156
|
+
question: _('If you have a name for your module, add it here.'),
|
157
|
+
help: _('This is the name that will be associated with your module, it should be relevant to the modules content.'),
|
158
|
+
required: true,
|
159
|
+
validate_pattern: %r{\A[a-z0-9]+\Z}i,
|
160
|
+
validate_message: _('Module names can only contain lowercase letters and numbers'),
|
161
|
+
},
|
162
|
+
{
|
163
|
+
name: 'forge_username',
|
174
164
|
question: _('If you have a Puppet Forge username, add it here.'),
|
175
165
|
help: _('We can use this to upload your module to the Forge when it\'s complete.'),
|
176
166
|
required: true,
|
177
167
|
validate_pattern: %r{\A[a-z0-9]+\Z}i,
|
178
168
|
validate_message: _('Forge usernames can only contain lowercase letters and numbers'),
|
179
|
-
default:
|
169
|
+
default: opts[:username],
|
180
170
|
},
|
181
171
|
{
|
182
172
|
name: 'version',
|
@@ -290,6 +280,7 @@ module PDK
|
|
290
280
|
|
291
281
|
interview = PDK::CLI::Util::Interview.new(prompt)
|
292
282
|
|
283
|
+
questions.reject! { |q| q[:name] == 'module_name' } if opts.key?(:module_name)
|
293
284
|
questions.reject! { |q| q[:name] == 'license' } if opts.key?(:license)
|
294
285
|
|
295
286
|
interview.add_questions(questions)
|
@@ -305,39 +296,37 @@ module PDK
|
|
305
296
|
answers = interview.run
|
306
297
|
|
307
298
|
if answers.nil?
|
308
|
-
PDK.logger.info _('
|
299
|
+
PDK.logger.info _('No answers given, interview cancelled.')
|
309
300
|
exit 0
|
310
301
|
end
|
311
302
|
|
312
|
-
|
313
|
-
answers['
|
303
|
+
opts[:username] = answers['forge_username']
|
304
|
+
opts[:module_name] = answers['module_name'] unless answers['module_name'].nil?
|
305
|
+
|
306
|
+
answers['name'] = "#{opts[:username]}-" + (opts[:module_name])
|
314
307
|
answers['license'] = opts[:license] if opts.key?(:license)
|
315
308
|
answers['operatingsystem_support'].flatten!
|
309
|
+
|
310
|
+
answers.delete('forge_username')
|
311
|
+
answers.delete('module_name')
|
312
|
+
|
316
313
|
metadata.update!(answers)
|
317
314
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
315
|
+
if opts[:prompt].nil? || opts[:prompt]
|
316
|
+
continue = PDK::CLI::Util.prompt_for_yes(
|
317
|
+
_('Metadata will be generated based on this information, continue?'),
|
318
|
+
prompt: prompt,
|
319
|
+
cancel_message: _('Interview cancelled; exiting.'),
|
320
|
+
)
|
324
321
|
|
325
|
-
|
326
|
-
|
327
|
-
|
322
|
+
unless continue
|
323
|
+
PDK.logger.info _('Process cancelled; exiting.')
|
324
|
+
exit 0
|
328
325
|
end
|
329
|
-
rescue TTY::Prompt::Reader::InputInterrupt
|
330
|
-
PDK.logger.info _('Interview cancelled; not generating the module.')
|
331
|
-
exit 0
|
332
|
-
end
|
333
|
-
|
334
|
-
unless continue
|
335
|
-
PDK.logger.info _('Module not generated.')
|
336
|
-
exit 0
|
337
326
|
end
|
338
327
|
|
339
328
|
PDK.answers.update!(
|
340
|
-
'
|
329
|
+
'forge_username' => opts[:username],
|
341
330
|
'author' => answers['author'],
|
342
331
|
'license' => answers['license'],
|
343
332
|
)
|