mirror of
https://github.com/golang/go
synced 2024-11-23 04:00:03 -07:00
misc/sortac: delete sortac command
The sortac command is no longer needed as of CL 157238, and can be deleted. Its functionality has been directly integrated into the new x/build/cmd/updatecontrib command. A previous version of updatecontrib was the only user of sortac. Updates #12042 Change-Id: If7442ebee11d05d095ff875a37eed3973c0fd9ca Reviewed-on: https://go-review.googlesource.com/c/157257 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
7502ed3b90
commit
e1d20ce25a
@ -1,79 +0,0 @@
|
||||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Sortac sorts the AUTHORS and CONTRIBUTORS files.
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// sortac [file...]
|
||||
//
|
||||
// Sortac sorts the named files in place.
|
||||
// If given no arguments, it sorts standard input to standard output.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"golang.org/x/text/collate"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.SetFlags(0)
|
||||
log.SetPrefix("sortac: ")
|
||||
flag.Parse()
|
||||
|
||||
args := flag.Args()
|
||||
if len(args) == 0 {
|
||||
os.Stdout.Write(sortAC(os.Stdin))
|
||||
} else {
|
||||
for _, arg := range args {
|
||||
f, err := os.Open(arg)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
sorted := sortAC(f)
|
||||
f.Close()
|
||||
if err := ioutil.WriteFile(arg, sorted, 0644); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func sortAC(r io.Reader) []byte {
|
||||
bs := bufio.NewScanner(r)
|
||||
var header []string
|
||||
var lines []string
|
||||
for bs.Scan() {
|
||||
t := bs.Text()
|
||||
lines = append(lines, t)
|
||||
if t == "# Please keep the list sorted." {
|
||||
header = lines
|
||||
lines = nil
|
||||
continue
|
||||
}
|
||||
}
|
||||
if err := bs.Err(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var out bytes.Buffer
|
||||
c := collate.New(language.Und, collate.Loose)
|
||||
c.SortStrings(lines)
|
||||
for _, l := range header {
|
||||
fmt.Fprintln(&out, l)
|
||||
}
|
||||
for _, l := range lines {
|
||||
fmt.Fprintln(&out, l)
|
||||
}
|
||||
return out.Bytes()
|
||||
}
|
Loading…
Reference in New Issue
Block a user