1
0
Fork 0
Dieser Commit ist enthalten in:
Stephen McQuay 2017-11-26 09:29:04 -08:00
Commit 7d36ec54f8
Signiert von: sm
GPG-Schlüssel-ID: 4E4B72F479BA3CE5
6 geänderte Dateien mit 120 neuen und 0 gelöschten Zeilen

1
.gitignore vendored Normale Datei
Datei anzeigen

@ -0,0 +1 @@
vendor

15
Gopkg.lock generiert Normale Datei
Datei anzeigen

@ -0,0 +1,15 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
name = "github.com/blang/semver"
packages = ["."]
revision = "2ee87856327ba09384cabd113bc6b5d174e9ec0f"
version = "v3.5.1"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "cf275d59cebaefe47525b0117f6f4cf189794057612c947e60cfe7e280335ee6"
solver-name = "gps-cdcl"
solver-version = 1

26
Gopkg.toml Normale Datei
Datei anzeigen

@ -0,0 +1,26 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
[[constraint]]
name = "github.com/blang/semver"
version = "3.5.1"

20
LICENSE Normale Datei
Datei anzeigen

@ -0,0 +1,20 @@
MIT License
Copyright (c) 2016 Stephen McQuay
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

3
README.md Normale Datei
Datei anzeigen

@ -0,0 +1,3 @@
# svsort
Sort lines of text that begin with semver.

55
main.go Normale Datei
Datei anzeigen

@ -0,0 +1,55 @@
// command svsort sorts lines of text by semver at beginning of line
package main
import (
"bufio"
"fmt"
"log"
"os"
"sort"
"strings"
"github.com/blang/semver"
)
type line struct {
v semver.Version
line string
}
type lines []line
func (l lines) Len() int { return len(l) }
func (l lines) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
func (l lines) Less(i, j int) bool { return l[i].v.LT(l[j].v) }
func main() {
s := bufio.NewScanner(os.Stdin)
ls := lines{}
for s.Scan() {
f := strings.Fields(s.Text())
if len(f) < 2 {
continue
}
v, err := semver.ParseTolerant(f[0])
if err != nil {
log.Printf("%v: %q", err, s.Text())
continue
}
l := line{
v: v,
line: s.Text(),
}
ls = append(ls, l)
}
if err := s.Err(); err != nil {
log.Fatalf("scan: %v")
}
sort.Sort(ls)
for _, l := range ls {
fmt.Printf("%v\n", l.line)
}
}