semver_dialects 3.4.4 → 3.5.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc2af1e2174290f8a8cd2fb277a61afa45dbd9302ec691660abf70299a5cb3ea
|
4
|
+
data.tar.gz: e116f449ba71422cedd8bf653f36d4fff5962970c4047e55b28dcbb02998cea2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee252fb5020e0800d152ff1f9739548c4a05f1a5f346060fe3a98b169ac9502e15be0831ed0a0d72efb911bfc96f0ba2c3871946963a7f86c07edc76fa94e835
|
7
|
+
data.tar.gz: f116913441d75cfedd96112a034b75a320e47356cd03f87eaeeafa8829c81db625509494e1ea92097530e3bf9e9e88d25d6fe31be639adc9ef57554c73b956ef
|
data/lib/semver_dialects/cli.rb
CHANGED
@@ -30,5 +30,20 @@ module SemverDialects
|
|
30
30
|
exit(ecode)
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
desc 'sort TYPE VERSIONS...', 'Sort a list of versions according to the specified package type'
|
35
|
+
method_option :help, aliases: '-h', type: :boolean,
|
36
|
+
desc: 'Display usage information'
|
37
|
+
method_option :json, type: :boolean,
|
38
|
+
desc: 'Output results in JSON format'
|
39
|
+
def sort(type, *versions)
|
40
|
+
if options[:help]
|
41
|
+
invoke :help, ['sort']
|
42
|
+
else
|
43
|
+
require_relative 'commands/sort_versions'
|
44
|
+
ecode = SemverDialects::Commands::SortVersions.new(type, versions, options).execute
|
45
|
+
exit(ecode)
|
46
|
+
end
|
47
|
+
end
|
33
48
|
end
|
34
49
|
end
|
@@ -12,12 +12,10 @@ module SemverDialects
|
|
12
12
|
@version = version
|
13
13
|
@constraint = constraint
|
14
14
|
@options = options
|
15
|
-
@avail_types = %w[gem npm ruby pypi php maven go]
|
16
15
|
end
|
17
16
|
|
18
17
|
def execute(_input: $stdin, output: $stdout)
|
19
18
|
typ = @type.downcase
|
20
|
-
raise SemverDialects::Error, 'wrong package type' unless @avail_types.include?(typ)
|
21
19
|
|
22
20
|
if SemverDialects.version_satisfies?(typ, @version, @constraint)
|
23
21
|
output.puts "#{@version} matches #{@constraint} for #{@type}"
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../command'
|
4
|
+
require_relative '../../semver_dialects'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module SemverDialects
|
8
|
+
module Commands
|
9
|
+
# The sort command implementation
|
10
|
+
class SortVersions < SemverDialects::Command
|
11
|
+
def initialize(type, versions, options) # rubocop:disable Lint/MissingSuper
|
12
|
+
@type = type.downcase
|
13
|
+
@versions = versions
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute(_input: $stdin, output: $stdout)
|
18
|
+
sorted_versions = []
|
19
|
+
invalid_versions = []
|
20
|
+
|
21
|
+
@versions.each do |version|
|
22
|
+
parsed_version = SemverDialects.parse_version(@type, version)
|
23
|
+
sorted_versions << parsed_version
|
24
|
+
rescue SemverDialects::InvalidVersionError, SemverDialects::UnsupportedVersionError => e
|
25
|
+
invalid_versions << { version: version, error: e.message }
|
26
|
+
end
|
27
|
+
|
28
|
+
sorted_versions.sort!
|
29
|
+
|
30
|
+
if @options[:json]
|
31
|
+
result = {
|
32
|
+
versions: sorted_versions.map(&:to_s),
|
33
|
+
invalid: invalid_versions.map { |v| v[:version] }
|
34
|
+
}
|
35
|
+
output.puts JSON.generate(result)
|
36
|
+
else
|
37
|
+
invalid_versions.each do |invalid|
|
38
|
+
output.puts "Warning: Invalid version '#{invalid[:version]}' - #{invalid[:error]}"
|
39
|
+
end
|
40
|
+
output.puts "Sorted versions: #{sorted_versions.map(&:to_s).join(', ')}"
|
41
|
+
end
|
42
|
+
|
43
|
+
0
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/semver_dialects.rb
CHANGED
@@ -26,7 +26,8 @@ module SemverDialects # rubocop:todo Style/Documentation
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def message
|
29
|
-
|
29
|
+
supported_types = SemverDialects.supported_package_types.join(', ')
|
30
|
+
"unsupported package type '#{@pkg_type}'. Supported types are: #{supported_types}"
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
@@ -113,6 +114,11 @@ module SemverDialects # rubocop:todo Style/Documentation
|
|
113
114
|
v1 < v2
|
114
115
|
end
|
115
116
|
|
117
|
+
# Returns array of supported package types
|
118
|
+
def self.supported_package_types
|
119
|
+
%w[maven npm go pypi nuget gem packagist conan cargo apk deb rpm]
|
120
|
+
end
|
121
|
+
|
116
122
|
# Parse a version according to the syntax type.
|
117
123
|
def self.parse_version(typ, raw_ver)
|
118
124
|
# for efficiency most popular package types come first
|
@@ -122,7 +128,7 @@ module SemverDialects # rubocop:todo Style/Documentation
|
|
122
128
|
|
123
129
|
when 'npm'
|
124
130
|
# npm follows Semver 2.0.0.
|
125
|
-
Semver2::VersionParser.parse(raw_ver)
|
131
|
+
Semver2::VersionParser.parse(cleanup(raw_ver))
|
126
132
|
|
127
133
|
when 'go'
|
128
134
|
# Go follows Semver 2.0.0.
|
@@ -228,4 +234,9 @@ module SemverDialects # rubocop:todo Style/Documentation
|
|
228
234
|
# Gem::Version.new raises an ArgumentError for invalid versions.
|
229
235
|
raise InvalidVersionError, raw_ver
|
230
236
|
end
|
237
|
+
|
238
|
+
# cleanup loose npm versions
|
239
|
+
def self.cleanup(raw_ver)
|
240
|
+
raw_ver.strip.gsub(/^[=v]/, '')
|
241
|
+
end
|
231
242
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semver_dialects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Thome
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2025-01-31 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: pastel
|
@@ -197,6 +197,7 @@ files:
|
|
197
197
|
- lib/semver_dialects/cli.rb
|
198
198
|
- lib/semver_dialects/command.rb
|
199
199
|
- lib/semver_dialects/commands/check_version.rb
|
200
|
+
- lib/semver_dialects/commands/sort_versions.rb
|
200
201
|
- lib/semver_dialects/interval.rb
|
201
202
|
- lib/semver_dialects/interval_parser.rb
|
202
203
|
- lib/semver_dialects/interval_set.rb
|