This commit is contained in:
Colin Marc 2015-01-06 12:05:17 +01:00
Родитель efbd8f615e
Коммит c8bc953e4d
11 изменённых файлов: 26 добавлений и 54 удалений

Просмотреть файл

@ -11,7 +11,7 @@ import (
var tailSearchSize int64 = 16384
func cat(paths []string) int {
func cat(paths []string) {
expanded, client, err := getClientAndExpandedPaths(paths)
if err != nil {
fatal(err)
@ -33,11 +33,9 @@ func cat(paths []string) int {
if err != nil {
fatal(err)
}
return 0
}
func printSection(paths []string, numLines, numBytes int64, fromEnd bool) int {
func printSection(paths []string, numLines, numBytes int64, fromEnd bool) {
if numLines != -1 && numBytes != -1 {
fatal("You can't specify both -n and -c.")
} else if numLines == -1 && numBytes == -1 {
@ -49,7 +47,6 @@ func printSection(paths []string, numLines, numBytes int64, fromEnd bool) int {
fatal(err)
}
status := 0
for _, p := range expanded {
file, err := client.Open(p)
if err != nil || file.Stat().IsDir() {
@ -82,8 +79,6 @@ func printSection(paths []string, numLines, numBytes int64, fromEnd bool) int {
io.Copy(os.Stdout, reader)
}
}
return status
}
func headLines(file *hdfs.FileReader, numLines int64) {

Просмотреть файл

@ -5,7 +5,7 @@ import (
"fmt"
)
func checksum(paths []string) int {
func checksum(paths []string) {
expanded, client, err := getClientAndExpandedPaths(paths)
if err != nil {
fatal(err)
@ -24,6 +24,4 @@ func checksum(paths []string) int {
fmt.Println(hex.EncodeToString(checksum), p)
}
return 0
}

Просмотреть файл

@ -6,7 +6,7 @@ import (
"strconv"
)
func chmod(args []string, recursive bool) int {
func chmod(args []string, recursive bool) {
if len(args) < 2 {
printHelp()
}
@ -21,7 +21,6 @@ func chmod(args []string, recursive bool) int {
fatal(err)
}
status := 0
visit := func(p string, fi os.FileInfo) {
err := client.Chmod(p, os.FileMode(mode))
@ -47,6 +46,4 @@ func chmod(args []string, recursive bool) int {
visit(p, info)
}
}
return status
}

Просмотреть файл

@ -6,7 +6,7 @@ import (
"strings"
)
func chown(args []string, recursive bool) int {
func chown(args []string, recursive bool) {
if len(args) < 2 {
printHelp()
}
@ -30,7 +30,6 @@ func chown(args []string, recursive bool) int {
fatal(err)
}
status := 0
visit := func(p string, fi os.FileInfo) {
err := client.Chown(p, owner, group)
@ -56,6 +55,4 @@ func chown(args []string, recursive bool) int {
visit(p, info)
}
}
return status
}

Просмотреть файл

@ -9,7 +9,7 @@ import (
"strings"
)
func get(args []string) int {
func get(args []string) {
if len(args) == 0 || len(args) > 2 {
printHelp()
}
@ -59,11 +59,9 @@ func get(args []string) int {
if err != nil {
fatal(err)
}
return 0
}
func getmerge(args []string, addNewlines bool) int {
func getmerge(args []string, addNewlines bool) {
if len(args) != 2 {
printHelp()
}
@ -112,6 +110,4 @@ func getmerge(args []string, addNewlines bool) int {
if err != nil {
fatal(err)
}
return 0
}

Просмотреть файл

@ -6,13 +6,13 @@ import (
"io"
"os"
"path"
"strings"
"strconv"
"strings"
"text/tabwriter"
"time"
)
func ls(paths []string, long, all, humanReadable bool) int {
func ls(paths []string, long, all, humanReadable bool) {
paths, client, err := getClientAndExpandedPaths(paths)
if err != nil {
fatal(err)
@ -64,8 +64,6 @@ func ls(paths []string, long, all, humanReadable bool) int {
printDir(client, dir, long, all, humanReadable)
}
}
return 0
}
func printDir(client *hdfs.Client, dir string, long, all, humanReadable bool) {

Просмотреть файл

@ -63,6 +63,7 @@ Valid commands:
getmergen = getmergeOpts.Bool('n')
cachedClient *hdfs.Client
status = 0
)
func init() {
@ -81,41 +82,40 @@ func main() {
command := os.Args[1]
argv := os.Args[1:]
status := 0
switch command {
case "ls":
lsOpts.Parse(argv)
status = ls(lsOpts.Args(), *lsl, *lsa, *lsh)
ls(lsOpts.Args(), *lsl, *lsa, *lsh)
case "rm":
rmOpts.Parse(argv)
status = rm(rmOpts.Args(), *rmr, *rmf)
rm(rmOpts.Args(), *rmr, *rmf)
case "mv":
mvOpts.Parse(argv)
status = mv(mvOpts.Args(), *mvf, *mvT)
mv(mvOpts.Args(), *mvf, *mvT)
case "mkdir":
mkdirOpts.Parse(argv)
status = mkdir(mkdirOpts.Args(), *mkdirp)
mkdir(mkdirOpts.Args(), *mkdirp)
case "touch":
touchOpts.Parse(argv)
status = touch(touchOpts.Args(), *touchc)
touch(touchOpts.Args(), *touchc)
case "chown":
chownOpts.Parse(argv)
status = chown(chownOpts.Args(), *chownR)
chown(chownOpts.Args(), *chownR)
case "chmod":
chmodOpts.Parse(argv)
status = chmod(chmodOpts.Args(), *chmodR)
chmod(chmodOpts.Args(), *chmodR)
case "cat":
status = cat(argv[1:])
cat(argv[1:])
case "head", "tail":
headTailOpts.Parse(argv)
status = printSection(headTailOpts.Args(), *headtailn, *headtailc, (command == "tail"))
printSection(headTailOpts.Args(), *headtailn, *headtailc, (command == "tail"))
case "checksum":
status = checksum(argv[1:])
checksum(argv[1:])
case "get":
status = get(argv[1:])
get(argv[1:])
case "getmerge":
getmergeOpts.Parse(argv)
status = getmerge(getmergeOpts.Args(), *getmergen)
getmerge(getmergeOpts.Args(), *getmergen)
// it's a seeeeecret command
case "complete":
complete(argv)

Просмотреть файл

@ -4,7 +4,7 @@ import (
"os"
)
func mkdir(paths []string, all bool) int {
func mkdir(paths []string, all bool) {
paths, nn, err := normalizePaths(paths)
if err != nil {
fatal(err)
@ -35,6 +35,4 @@ func mkdir(paths []string, all bool) int {
fatal(err)
}
}
return 0
}

Просмотреть файл

@ -6,7 +6,7 @@ import (
"path"
)
func mv(paths []string, force, treatDestAsFile bool) int {
func mv(paths []string, force, treatDestAsFile bool) {
paths, nn, err := normalizePaths(paths)
if err != nil {
fatal(err)
@ -44,8 +44,6 @@ func mv(paths []string, force, treatDestAsFile bool) int {
moveTo(client, sources[0], dest, force)
}
return 0
}
func moveInto(client *hdfs.Client, sources []string, dest string, force bool) {

Просмотреть файл

@ -6,13 +6,12 @@ import (
"os"
)
func rm(paths []string, recursive bool, force bool) int {
func rm(paths []string, recursive bool, force bool) {
expanded, client, err := getClientAndExpandedPaths(paths)
if err != nil {
fatal(err)
}
status := 0
for _, p := range expanded {
info, err := client.Stat(p)
if err != nil {
@ -40,6 +39,4 @@ func rm(paths []string, recursive bool, force bool) int {
fatal(err)
}
}
return status
}

Просмотреть файл

@ -5,7 +5,7 @@ import (
"time"
)
func touch(paths []string, noCreate bool) int {
func touch(paths []string, noCreate bool) {
paths, nn, err := normalizePaths(paths)
if err != nil {
fatal(err)
@ -45,6 +45,4 @@ func touch(paths []string, noCreate bool) int {
fatal(err)
}
}
return 0
}