]> Sergey Matveev's repositories - meta4ra.git/commitdiff
Inverse sorting ability v1.5.0
authorSergey Matveev <stargrave@stargrave.org>
Fri, 27 Feb 2026 12:12:06 +0000 (15:12 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 27 Feb 2026 12:25:36 +0000 (15:25 +0300)
cmd/sort.go
internal/common.go

index 016bb7aa315c90af54c04c366b1fd8ca915045e8..7b19acf9a65f707386a42cf398ac91c34ea19a5b 100644 (file)
@@ -24,6 +24,7 @@ import (
        "net"
        "net/url"
        "os"
+       "slices"
        "sort"
        "strings"
 
@@ -82,7 +83,8 @@ func runURLSort() {
                flag.PrintDefaults()
                fmt.Fprint(flag.CommandLine.Output(), `
 By default all URLs are sorted by priority. If "cc"s are specified, then
-sort by them with descending order. If "cc" is "rand", then shuffle URLs.
+sort by them with descending order. By specifying "!" before "cc", you
+inverse the order. If "cc" is "rand", then shuffle URLs.
 For specifying the region/continent use:
     c:af -- Africa
     c:an -- Antarctica
@@ -92,8 +94,9 @@ For specifying the region/continent use:
     c:oc -- Oceania
     c:sa -- South America
 For example to set Russia first, then Germany and France of same order,
-then Europe, then North America, then location-less, randomise remaining:
-    ru "de fr" c:eu c:na "" rand
+then Europe, then North America, least priority Ukraine, then location-less,
+randomise remaining:
+    ru "de fr" "!ua" c:eu c:na "" rand
 `)
        }
        flag.Parse()
@@ -130,14 +133,21 @@ then Europe, then North America, then location-less, randomise remaining:
                        rand.Shuffle(len(urls), func(i, j int) {
                                urls[i], urls[j] = urls[j], urls[i]
                        })
+                       continue
+               }
+               invert := false
+               if len(cc) > 0 && cc[0] == '!' {
+                       invert = true
+                       cc = cc[1:]
+                       slices.Reverse(urls)
                }
                if strings.HasPrefix(cc, "c:") {
                        cc = Continents[cc[2:]]
                }
-               sort.Stable(ByCC{
-                       cc:   cc,
-                       urls: urls,
-               })
+               sort.Stable(ByCC{cc: cc, urls: urls})
+               if invert {
+                       slices.Reverse(urls)
+               }
        }
        sort.Stable(ByPriority(urls))
        for _, u := range urls {
index 8c47706004174f08414b84ebc4f69f8b02a4142f..dc6b781d39e994efca71a511eada5846385facd3 100644 (file)
@@ -21,7 +21,7 @@ import (
 )
 
 const (
-       Generator       = "meta4ra/1.4.0"
+       Generator       = "meta4ra/1.5.0"
        SigMediaTypePGP = "application/pgp-signature"
        SigMediaTypeSSH = "application/ssh-signature"
        BufLen          = 1 << 20