pray-cli 1.9.0 → 1.9.1
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 +3 -1
- data/lib/pray/manifest_constraint.rb +67 -0
- data/lib/pray/manifest_formatter.rb +10 -6
- data/lib/pray/version.rb +2 -2
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4aabea84f997a26ce08fd78e561be889a990f16fde64956f55ea92249b2d13b0
|
|
4
|
+
data.tar.gz: 360408860ba9184cfa6e09434092f2758b4bdced69a7d3873288b54157450e63
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d4703291e60da15ad0109712fc07e6e4f5dbd35efeafd3e8e49f86ccdbddaad39b3f5faca751f80662f618abcb3f618d4c0d4ea5962a470ef5c417ef94112e08
|
|
7
|
+
data.tar.gz: 68b4a7df9a8a0aef4879ff2ef1f101068b494baafef3ddc869385f7565cb4cdaf4afe42ea35c4966f2e090cf21461bdac021f3fcb64fd44ac1cadc00b29561dc
|
data/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Pray
|
|
4
|
+
module ManifestMethods
|
|
5
|
+
module_function
|
|
6
|
+
|
|
7
|
+
PACKAGE_KEYWORDS = %w[pray use include agent package].freeze
|
|
8
|
+
|
|
9
|
+
def rewrite_constraint_on_line(line, constraint)
|
|
10
|
+
indent = line[/\A\s*/]
|
|
11
|
+
trimmed = line.lstrip
|
|
12
|
+
after_keyword = skip_package_keyword(trimmed)
|
|
13
|
+
raise Error.manifest("package declaration is missing a keyword") unless after_keyword
|
|
14
|
+
|
|
15
|
+
after_keyword = after_keyword.lstrip
|
|
16
|
+
parsed_name = parse_quoted(after_keyword)
|
|
17
|
+
raise Error.manifest("package declaration is missing a quoted name") unless parsed_name
|
|
18
|
+
|
|
19
|
+
name, after_name = parsed_name
|
|
20
|
+
quoted_constraint = "\"#{constraint}\""
|
|
21
|
+
keyword_and_name = trimmed[0, trimmed.length - after_name.length]
|
|
22
|
+
remainder = after_name.lstrip
|
|
23
|
+
return "#{indent}#{keyword_and_name}, #{quoted_constraint}" if remainder.empty?
|
|
24
|
+
unless remainder.start_with?(",")
|
|
25
|
+
raise Error.manifest("package #{name} declaration is missing a comma after the name")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
after_comma = remainder[1..].lstrip
|
|
29
|
+
if after_comma.start_with?("\"", "'")
|
|
30
|
+
parsed_constraint = parse_quoted(after_comma)
|
|
31
|
+
unless parsed_constraint
|
|
32
|
+
raise Error.manifest("package #{name} declaration has an unclosed constraint")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
return "#{indent}#{keyword_and_name}, #{quoted_constraint}#{parsed_constraint[1]}"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
"#{indent}#{keyword_and_name}, #{quoted_constraint}, #{after_comma}"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def skip_package_keyword(input)
|
|
42
|
+
PACKAGE_KEYWORDS.each do |keyword|
|
|
43
|
+
next unless input.start_with?(keyword)
|
|
44
|
+
|
|
45
|
+
rest = input[keyword.length..]
|
|
46
|
+
next_character = rest[0]
|
|
47
|
+
whitespace_or_quote = next_character.nil? ||
|
|
48
|
+
next_character.match?(/\s/) ||
|
|
49
|
+
next_character == "\"" ||
|
|
50
|
+
next_character == "'"
|
|
51
|
+
return rest if whitespace_or_quote
|
|
52
|
+
end
|
|
53
|
+
nil
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def parse_quoted(input)
|
|
57
|
+
quote = input[0]
|
|
58
|
+
return unless quote == "\"" || quote == "'"
|
|
59
|
+
|
|
60
|
+
rest = input[1..]
|
|
61
|
+
ending = rest.index(quote)
|
|
62
|
+
return unless ending
|
|
63
|
+
|
|
64
|
+
[rest[0, ending], rest[(ending + 1)..]]
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "manifest_constraint"
|
|
4
|
+
|
|
3
5
|
module Pray
|
|
4
6
|
module ManifestMethods
|
|
5
7
|
module_function
|
|
@@ -37,13 +39,15 @@ module Pray
|
|
|
37
39
|
"package \"#{name}\"", "package '#{name}'"
|
|
38
40
|
]
|
|
39
41
|
lines = text.lines.map(&:chomp)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
raise Error.manifest("package #{name} not found in manifest") unless index
|
|
42
|
+
replaced = 0
|
|
43
|
+
lines.each_index do |index|
|
|
44
|
+
trimmed = lines[index].lstrip
|
|
45
|
+
next unless prefixes.any? { |prefix| trimmed.start_with?(prefix) }
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
lines[index] = rewrite_constraint_on_line(lines[index], package.constraint)
|
|
48
|
+
replaced += 1
|
|
49
|
+
end
|
|
50
|
+
raise Error.manifest("package #{name} not found in manifest") if replaced.zero?
|
|
47
51
|
output = lines.join("\n")
|
|
48
52
|
output += "\n" if text.end_with?("\n") && !output.end_with?("\n")
|
|
49
53
|
output
|
data/lib/pray/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pray-cli
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.9.
|
|
4
|
+
version: 1.9.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrei Makarov
|
|
@@ -128,6 +128,7 @@ files:
|
|
|
128
128
|
- lib/pray/lockfile.rb
|
|
129
129
|
- lib/pray/lockfile_serialize.rb
|
|
130
130
|
- lib/pray/manifest.rb
|
|
131
|
+
- lib/pray/manifest_constraint.rb
|
|
131
132
|
- lib/pray/manifest_formatter.rb
|
|
132
133
|
- lib/pray/manifest_json.rb
|
|
133
134
|
- lib/pray/manifest_parser.rb
|