semver_dialects 3.4.5 → 3.6.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/lib/semver_dialects/cli.rb +15 -0
- data/lib/semver_dialects/commands/check_version.rb +0 -2
- data/lib/semver_dialects/commands/sort_versions.rb +47 -0
- data/lib/semver_dialects/interval.rb +4 -0
- data/lib/semver_dialects/interval_set.rb +4 -0
- data/lib/semver_dialects/interval_set_parser.rb +6 -0
- data/lib/semver_dialects/version.rb +1 -1
- data/lib/semver_dialects.rb +11 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe0a320a210aa3cf18ef447c32c3d2d461bba51c185df2dbd842b6ce5ce7815a
|
4
|
+
data.tar.gz: 38f73e2943f151051181bc4a60e2df97dfcf341f6fad9404a25b344dd9d4b08a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35ca22a972575add479fec3ef5442f5fea5d652e896285183da75738207d7a65e2bf84abe66a2f6af27e1578b6272b6dc5ceb6f91bd731b45a49abb8031f23f4
|
7
|
+
data.tar.gz: 7e481a673228c2c843cf61f2d179ebe3a52e3b37a99f5da83ad5f95edcb6a56ec758fe2b96d9aeff1d209375626c335af6c5135bfa44daddf571ea185fb2c72a
|
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
|
@@ -34,6 +34,8 @@ module SemverDialects
|
|
34
34
|
translate_packagist(interval_set_string)
|
35
35
|
when 'cargo'
|
36
36
|
translate_cargo(interval_set_string)
|
37
|
+
when 'swift'
|
38
|
+
translate_swift(interval_set_string)
|
37
39
|
else
|
38
40
|
raise UnsupportedPackageTypeError, typ
|
39
41
|
end
|
@@ -81,6 +83,10 @@ module SemverDialects
|
|
81
83
|
translate_npm(interval_set_string)
|
82
84
|
end
|
83
85
|
|
86
|
+
def self.translate_swift(interval_set_string)
|
87
|
+
translate_npm(interval_set_string)
|
88
|
+
end
|
89
|
+
|
84
90
|
def self.add_missing_operator(interval_set_string)
|
85
91
|
starts_with_operator?(interval_set_string) ? interval_set_string : "=#{interval_set_string}"
|
86
92
|
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 swift]
|
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
|
@@ -215,6 +221,10 @@ module SemverDialects # rubocop:todo Style/Documentation
|
|
215
221
|
# cargo follows Semver 2.0.0.
|
216
222
|
Semver2::VersionParser.parse(raw_ver)
|
217
223
|
|
224
|
+
when 'swift'
|
225
|
+
# swift follows Semver 2.0.0.
|
226
|
+
Semver2::VersionParser.parse(raw_ver)
|
227
|
+
|
218
228
|
when 'apk'
|
219
229
|
Apk::VersionParser.parse(raw_ver)
|
220
230
|
when 'deb'
|
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.6.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-02-07 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
|