add mkdir [-p]
This commit is contained in:
Родитель
173f5af29d
Коммит
1ca4f96d79
|
@ -13,8 +13,9 @@ The flags available are a subset of the POSIX ones, but should behave similarly.
|
|||
|
||||
Valid commands:
|
||||
ls [-la] [FILE]...
|
||||
rm [-r] [FILE]...
|
||||
rm [-r] FILE...
|
||||
mv [-fT] SOURCE... DEST
|
||||
mkdir [-p] FILE...
|
||||
`, os.Args[0])
|
||||
|
||||
lsOpts = getopt.New()
|
||||
|
@ -27,6 +28,9 @@ Valid commands:
|
|||
mvOpts = getopt.New()
|
||||
mvf = mvOpts.Bool('f')
|
||||
mvT = mvOpts.Bool('T')
|
||||
|
||||
mkdirOpts = getopt.New()
|
||||
mkdirp = mkdirOpts.Bool('p')
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -52,6 +56,9 @@ func main() {
|
|||
case "mv":
|
||||
mvOpts.Parse(os.Args[1:])
|
||||
status = mv(mvOpts.Args(), *mvf, *mvT)
|
||||
case "mkdir":
|
||||
mkdirOpts.Parse(os.Args[1:])
|
||||
status = mkdir(mkdirOpts.Args(), *mkdirp)
|
||||
case "complete":
|
||||
var words []string
|
||||
if len(os.Args) == 3 {
|
||||
|
|
|
@ -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
|
||||
|
||||
import (
|
||||
"github.com/colinmarc/hdfs"
|
||||
"os"
|
||||
"path"
|
||||
"github.com/colinmarc/hdfs"
|
||||
)
|
||||
|
||||
func mv(paths []string, force, treatDestAsFile bool) int {
|
||||
|
|
Загрузка…
Ссылка в новой задаче