mkdir: First implementation.
This commit is contained in:
parent
73b6a04611
commit
d74cd0b6ef
6 changed files with 45 additions and 7 deletions
|
@ -1,2 +0,0 @@
|
|||
# goblin
|
||||
GO Base utiL ImplementatioN
|
5
README.txt
Normal file
5
README.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
# goblin
|
||||
GO Base utiL ImplementatioN
|
||||
Simple and crossplatform implementation of base(core) utils
|
||||
in highlevel Golang targeted to be easy to modify
|
||||
and implement new features.
|
40
mkdir/main.go
Normal file
40
mkdir/main.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package main
|
||||
|
||||
import(
|
||||
"os"
|
||||
"flag"
|
||||
"log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var (
|
||||
parentFlag, verbFlag bool
|
||||
modeArg int
|
||||
)
|
||||
flag.BoolVar(&parentFlag, "p", false, "No error if existing, make parent as needed.")
|
||||
flag.IntVar(&modeArg, "m", 0766, "Set file `mode`.")
|
||||
flag.BoolVar(&verbFlag, "v", false, "Print a message for each created directory.")
|
||||
if len(os.Args) < 2 {
|
||||
flag.Usage()
|
||||
}
|
||||
flag.Parse()
|
||||
mode := os.FileMode(modeArg)
|
||||
var verb *log.Logger
|
||||
if verbFlag {
|
||||
verb = log.New(os.Stdout, os.Args[0]+": ", 0)
|
||||
}
|
||||
warn := log.New(os.Stderr, os.Args[0]+": ", 0)
|
||||
for _, path := range flag.Args() {
|
||||
var err error
|
||||
if parentFlag {
|
||||
err = os.MkdirAll(path, mode)
|
||||
} else {
|
||||
err = os.Mkdir(path, mode)
|
||||
}
|
||||
if err != nil {
|
||||
warn.Println(err)
|
||||
} else if verbFlag {
|
||||
verb.Printf("Created directory '%s'.", path)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
New implementations with no dependence
|
||||
on POSIX and other old shit.
|
||||
There are too many stupid things
|
||||
on options to put all of this in
|
||||
one implementation only.
|
Loading…
Reference in a new issue