From: Sergey Matveev Date: Fri, 27 Feb 2026 12:12:06 +0000 (+0300) Subject: Inverse sorting ability X-Git-Tag: v1.5.0^0 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=f30f365ab3b7a7e5e496b34101eb9ab9a3ba10b9;p=meta4ra.git Inverse sorting ability --- diff --git a/cmd/sort.go b/cmd/sort.go index 016bb7a..7b19acf 100644 --- a/cmd/sort.go +++ b/cmd/sort.go @@ -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 { diff --git a/internal/common.go b/internal/common.go index 8c47706..dc6b781 100644 --- a/internal/common.go +++ b/internal/common.go @@ -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