This commit is contained in:
Colin Marc 2014-10-23 18:46:52 +02:00
Родитель 173f5af29d
Коммит 1ca4f96d79
3 изменённых файлов: 48 добавлений и 2 удалений

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

@ -13,8 +13,9 @@ The flags available are a subset of the POSIX ones, but should behave similarly.
Valid commands: Valid commands:
ls [-la] [FILE]... ls [-la] [FILE]...
rm [-r] [FILE]... rm [-r] FILE...
mv [-fT] SOURCE... DEST mv [-fT] SOURCE... DEST
mkdir [-p] FILE...
`, os.Args[0]) `, os.Args[0])
lsOpts = getopt.New() lsOpts = getopt.New()
@ -27,6 +28,9 @@ Valid commands:
mvOpts = getopt.New() mvOpts = getopt.New()
mvf = mvOpts.Bool('f') mvf = mvOpts.Bool('f')
mvT = mvOpts.Bool('T') mvT = mvOpts.Bool('T')
mkdirOpts = getopt.New()
mkdirp = mkdirOpts.Bool('p')
) )
func init() { func init() {
@ -52,6 +56,9 @@ func main() {
case "mv": case "mv":
mvOpts.Parse(os.Args[1:]) mvOpts.Parse(os.Args[1:])
status = mv(mvOpts.Args(), *mvf, *mvT) status = mv(mvOpts.Args(), *mvf, *mvT)
case "mkdir":
mkdirOpts.Parse(os.Args[1:])
status = mkdir(mkdirOpts.Args(), *mkdirp)
case "complete": case "complete":
var words []string var words []string
if len(os.Args) == 3 { if len(os.Args) == 3 {

39
cmd/hdfs/mkdir.go Normal file
Просмотреть файл

@ -0,0 +1,39 @@
package main
import (
"os"
)
func mkdir(paths []string, all bool) int {
paths, nn, err := normalizePaths(paths)
if err != nil {
fatal(err)
}
if len(paths) == 0 {
printHelp()
}
client, err := getClient(nn)
if err != nil {
fatal(err)
}
for _, p := range paths {
if hasGlob(p) {
fatal(fileError(p, os.ErrNotExist))
}
if all {
err = client.MkdirAll(p, 0644)
} else {
err = client.Mkdir(p, 0644)
}
if err != nil && !(all && err == os.ErrExist) {
fatal(fileError(p, err))
}
}
return 0
}

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

@ -1,9 +1,9 @@
package main package main
import ( import (
"github.com/colinmarc/hdfs"
"os" "os"
"path" "path"
"github.com/colinmarc/hdfs"
) )
func mv(paths []string, force, treatDestAsFile bool) int { func mv(paths []string, force, treatDestAsFile bool) int {