puppetfile_editor 0.4.0 → 0.5.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 +4 -0
- data/bin/pfile +11 -4
- data/lib/puppetfile_editor/cli.rb +22 -13
- data/lib/puppetfile_editor/module.rb +74 -73
- data/lib/puppetfile_editor/puppetfile.rb +7 -5
- data/lib/puppetfile_editor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc263a5f1856d71645fb70d268488605c16c3525
|
4
|
+
data.tar.gz: 19486c4caa8397f34aa7691917954cc88b35dcd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aad9c5681bc66503bc7521d13313f0ee3be222da26382deeaf24b28736f25305897be3edec8c2d1d175fcac480111c3457f983b8d55454888c535476954848ae
|
7
|
+
data.tar.gz: b3779e4a40716475e33f439281c359d4c8197c846356c0b866265574bbb44a29db210285d79856f3d2789b9fa467812edb199b2e9c2cb1a601ab899852ee23f0
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
6
6
|
|
7
|
+
## [0.5.0] - 2017-10-23
|
8
|
+
### Added
|
9
|
+
- `delete` command for deleting modules from Puppetfile.
|
10
|
+
|
7
11
|
## [0.4.0] - 2017-10-07
|
8
12
|
### Added
|
9
13
|
- Support for setting `changeset` for git/hg modules.
|
data/bin/pfile
CHANGED
@@ -11,7 +11,7 @@ ARGV.push('-h') if ARGV.empty?
|
|
11
11
|
options = { puppetfile: './Puppetfile' }
|
12
12
|
|
13
13
|
subcommands = {
|
14
|
-
'edit'
|
14
|
+
'edit' => OptionParser.new do |parser|
|
15
15
|
parser.banner = "Usage: #{filename} edit [options]"
|
16
16
|
parser.on('-m', '--module-name NAME', 'Module name') do |setting|
|
17
17
|
options[:name] = setting
|
@@ -23,7 +23,13 @@ subcommands = {
|
|
23
23
|
'format' => OptionParser.new do |parser|
|
24
24
|
parser.banner = "Usage: #{filename} format"
|
25
25
|
end,
|
26
|
-
'
|
26
|
+
'delete' => OptionParser.new do |parser|
|
27
|
+
parser.banner = "Usage: #{filename} format -m MODULENAME"
|
28
|
+
parser.on('-m', '--module-name NAME', 'Module name') do |setting|
|
29
|
+
options[:name] = setting
|
30
|
+
end
|
31
|
+
end,
|
32
|
+
'add' => OptionParser.new do |parser|
|
27
33
|
parser.banner = "Usage: #{filename} add [options]"
|
28
34
|
parser.on('-m', '--module-name NAME', 'Module name') do |setting|
|
29
35
|
options[:name] = setting
|
@@ -36,7 +42,8 @@ subcommands = {
|
|
36
42
|
end
|
37
43
|
parser.on('-u', '--version [PARAM=VALUE]', 'Version of module to add in the form of PARAM=VALUE') do |setting|
|
38
44
|
if (match = setting.match(/^(\w+)=([^=]+)$/))
|
39
|
-
options[:param]
|
45
|
+
options[:param] = match[1]
|
46
|
+
options[:value] = match[2]
|
40
47
|
elsif (match = setting.match(/^\d+(\.\d)*$/))
|
41
48
|
options[:version] = match[0]
|
42
49
|
else
|
@@ -45,7 +52,7 @@ subcommands = {
|
|
45
52
|
end
|
46
53
|
end
|
47
54
|
end,
|
48
|
-
'merge'
|
55
|
+
'merge' => OptionParser.new do |parser|
|
49
56
|
parser.banner = "Usage: #{filename} merge [options]"
|
50
57
|
parser.separator ' Merge existing Puppetfile with another one from STDIN.'
|
51
58
|
parser.separator ' Dump the result to STDOUT.'
|
@@ -37,22 +37,29 @@ module PuppetfileEditor
|
|
37
37
|
@pfile.dump
|
38
38
|
end
|
39
39
|
|
40
|
+
def delete(opts)
|
41
|
+
warn_and_exit "Module #{opts[:name]} does not exist in your Puppetfile." unless @pfile.modules.key? opts[:name]
|
42
|
+
|
43
|
+
@pfile.delete_module(opts[:name])
|
44
|
+
@pfile.dump
|
45
|
+
end
|
46
|
+
|
40
47
|
def add(opts)
|
41
48
|
warn_and_exit "Module #{opts[:name]} is already present in your Puppetfile." if @pfile.modules.key? opts[:name]
|
42
49
|
|
43
50
|
case opts[:type]
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
when :hg, :git
|
52
|
+
warn_and_exit 'URL must be provided for Git and Hg modules' unless opts.key? :url
|
53
|
+
warn_and_exit 'Version must be provided for Git and Hg modules' unless opts.key? :param
|
54
|
+
opts[:value] = :latest if opts[:value] == 'latest'
|
55
|
+
@pfile.add_module(opts[:name], opts[:type] => opts[:url], opts[:param] => opts[:value])
|
56
|
+
when :local
|
57
|
+
@pfile.add_module(opts[:name], :local)
|
58
|
+
when :forge
|
59
|
+
warn_and_exit 'Version must be provided for Forge modules' unless opts.key? :version
|
60
|
+
@pfile.add_module(opts[:name], opts[:version])
|
61
|
+
else
|
62
|
+
warn_and_exit 'Only hg, git, local, and forge modules are supported at the moment.'
|
56
63
|
end
|
57
64
|
@pfile.dump
|
58
65
|
end
|
@@ -95,6 +102,9 @@ module PuppetfileEditor
|
|
95
102
|
end
|
96
103
|
end
|
97
104
|
|
105
|
+
# Abstraction of logging methods for PuppetfileEditor::CLI
|
106
|
+
#
|
107
|
+
# @api private
|
98
108
|
class Logging
|
99
109
|
def initialize
|
100
110
|
@statuses = {
|
@@ -126,6 +136,5 @@ module PuppetfileEditor
|
|
126
136
|
def mod_message(mod, indent)
|
127
137
|
log("#{mod.name.ljust(indent)} => #{mod.message}", mod.status)
|
128
138
|
end
|
129
|
-
|
130
139
|
end
|
131
140
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module PuppetfileEditor
|
2
|
+
# Module class represents a puppet module in Puppetfile
|
2
3
|
class Module
|
3
4
|
attr_reader :type
|
4
5
|
attr_reader :params
|
@@ -30,29 +31,29 @@ module PuppetfileEditor
|
|
30
31
|
|
31
32
|
def set(param, newvalue, force = false)
|
32
33
|
case @type
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
else
|
39
|
-
set_message("updated (#{full_version} to #{param}: #{newvalue}", :updated)
|
40
|
-
@params.delete :branch
|
41
|
-
@params.delete :tag
|
42
|
-
@params.delete :ref
|
43
|
-
@params.delete :changeset
|
44
|
-
@params[param.to_sym] = newvalue
|
45
|
-
calculate_indent
|
46
|
-
end
|
47
|
-
when :forge
|
48
|
-
if param == 'version'
|
49
|
-
@params[:version] = newvalue
|
50
|
-
set_message("successfully set #{param} to #{newvalue} for #{@name}.", :updated)
|
51
|
-
else
|
52
|
-
set_message("only 'version' is supported for forge modules.", :unsupported)
|
53
|
-
end
|
34
|
+
when :hg, :git
|
35
|
+
if !force && !([:branch, :ref, :changeset] & @params.keys).empty?
|
36
|
+
set_message("kept at (#{full_version})", :wont_upgrade)
|
37
|
+
elsif !%w[branch tag ref changeset].include? param
|
38
|
+
set_message("only 'branch', 'tag', 'ref', and 'changeset' are supported for '#{@type}' modules.", :unsupported)
|
54
39
|
else
|
55
|
-
set_message("
|
40
|
+
set_message("updated (#{full_version} to #{param}: #{newvalue}", :updated)
|
41
|
+
@params.delete :branch
|
42
|
+
@params.delete :tag
|
43
|
+
@params.delete :ref
|
44
|
+
@params.delete :changeset
|
45
|
+
@params[param.to_sym] = newvalue
|
46
|
+
calculate_indent
|
47
|
+
end
|
48
|
+
when :forge
|
49
|
+
if param == 'version'
|
50
|
+
@params[:version] = newvalue
|
51
|
+
set_message("successfully set #{param} to #{newvalue} for #{@name}.", :updated)
|
52
|
+
else
|
53
|
+
set_message("only 'version' is supported for forge modules.", :unsupported)
|
54
|
+
end
|
55
|
+
else
|
56
|
+
set_message("editing params for '#{@type}' modules is not supported.", :unsupported)
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
@@ -62,62 +63,62 @@ module PuppetfileEditor
|
|
62
63
|
return
|
63
64
|
end
|
64
65
|
case @type
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
return
|
85
|
-
end
|
86
|
-
end
|
87
|
-
if full_version == mod.full_version
|
88
|
-
set_message("versions match (#{full_version})", :matched)
|
66
|
+
when :hg, :git
|
67
|
+
new = mod.params.reject { |param, _| param.eql? @type }
|
68
|
+
if !force && new.keys == [:tag] && !([:branch, :ref, :changeset] & @params.keys).empty?
|
69
|
+
set_message("kept at #{full_version}", :wont_upgrade)
|
70
|
+
return
|
71
|
+
end
|
72
|
+
if full_version == mod.full_version
|
73
|
+
set_message("versions match (#{full_version})", :matched)
|
74
|
+
return
|
75
|
+
else
|
76
|
+
set_message("updated (#{full_version} to #{mod.full_version})", :updated)
|
77
|
+
end
|
78
|
+
@params.delete_if { |param, _| [:branch, :tag, :ref, :changeset].include? param }
|
79
|
+
@params.merge!(new)
|
80
|
+
calculate_indent
|
81
|
+
when :forge
|
82
|
+
unless force
|
83
|
+
if mod.params.nil? || mod.params.is_a?(Symbol)
|
84
|
+
set_message("won't upgrade to #{mod.full_version}", :wont_upgrade)
|
89
85
|
return
|
90
|
-
else
|
91
|
-
set_message("updated (#{full_version} to #{mod.full_version})", :updated)
|
92
86
|
end
|
93
|
-
|
87
|
+
end
|
88
|
+
if full_version == mod.full_version
|
89
|
+
set_message("versions match (#{full_version})", :matched)
|
90
|
+
return
|
94
91
|
else
|
95
|
-
set_message(
|
92
|
+
set_message("updated (#{full_version} to #{mod.full_version})", :updated)
|
93
|
+
end
|
94
|
+
@params = mod.params
|
95
|
+
else
|
96
|
+
set_message('only git, forge, and hg modules are supported for merging', :skipped)
|
96
97
|
end
|
97
98
|
end
|
98
99
|
|
99
100
|
def dump
|
100
101
|
output = []
|
101
102
|
case @type
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
103
|
+
when :hg, :git
|
104
|
+
output.push "mod '#{full_title}'"
|
105
|
+
@params.each do |param_name, param_value|
|
106
|
+
value = if param_value == :latest
|
107
|
+
':latest'
|
108
|
+
else
|
109
|
+
"'#{param_value}'"
|
110
|
+
end
|
111
|
+
param = "#{param_name}:".ljust(@indent)
|
112
|
+
output.push " #{param} #{value}"
|
113
|
+
end
|
114
|
+
when :local
|
115
|
+
output.push("mod '#{full_title}', :local")
|
116
|
+
else
|
117
|
+
if @params.nil?
|
118
|
+
output.push("mod '#{full_title}'")
|
115
119
|
else
|
116
|
-
|
117
|
-
|
118
|
-
else
|
119
|
-
output.push("mod '#{full_title}', '#{@params[:version]}'")
|
120
|
-
end
|
120
|
+
output.push("mod '#{full_title}', '#{@params[:version]}'")
|
121
|
+
end
|
121
122
|
end
|
122
123
|
output.join(",\n")
|
123
124
|
end
|
@@ -129,11 +130,11 @@ module PuppetfileEditor
|
|
129
130
|
|
130
131
|
def full_version
|
131
132
|
case @type
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
133
|
+
when :hg, :git
|
134
|
+
@params.reject { |param, _| param.eql? @type }.map { |param, value| "#{param}: #{value}" }.sort.join(', ')
|
135
|
+
when :forge
|
136
|
+
return @params[:version] if @params.key? :version
|
137
|
+
nil
|
137
138
|
end
|
138
139
|
end
|
139
140
|
|
@@ -71,11 +71,9 @@ module PuppetfileEditor
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def update_module(name, param, value)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
raise StandardError, "Module #{name} does not exist in your Puppetfile"
|
78
|
-
end
|
74
|
+
raise StandardError, "Module #{name} does not exist in your Puppetfile" unless @modules.key? name
|
75
|
+
|
76
|
+
@modules[name].set(param, value, true)
|
79
77
|
end
|
80
78
|
|
81
79
|
def compare_with(pf)
|
@@ -108,6 +106,10 @@ module PuppetfileEditor
|
|
108
106
|
@modules[mod.name] = mod
|
109
107
|
end
|
110
108
|
|
109
|
+
def delete_module(name)
|
110
|
+
@modules.delete(name)
|
111
|
+
end
|
112
|
+
|
111
113
|
def update_forge_url(url)
|
112
114
|
raise StandardError, "Forge URL must be a String, but it is a #{url.class}" unless url.is_a? String
|
113
115
|
@forge = url
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppetfile_editor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Piven
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|