From d74cd0b6eff9028589539f7d94eab88a253828e1 Mon Sep 17 00:00:00 2001 From: jienfak Date: Sat, 28 Sep 2019 17:11:32 +0500 Subject: [PATCH] mkdir: First implementation. --- LICENSE => LICENSE.txt | 0 README.md | 2 -- README.txt | 5 +++++ {newnix/echo => echo}/main.go | 0 mkdir/main.go | 40 +++++++++++++++++++++++++++++++++++ newnix/README.txt | 5 ----- 6 files changed, 45 insertions(+), 7 deletions(-) rename LICENSE => LICENSE.txt (100%) delete mode 100644 README.md create mode 100644 README.txt rename {newnix/echo => echo}/main.go (100%) create mode 100644 mkdir/main.go delete mode 100644 newnix/README.txt diff --git a/LICENSE b/LICENSE.txt similarity index 100% rename from LICENSE rename to LICENSE.txt diff --git a/README.md b/README.md deleted file mode 100644 index 9932ec6..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# goblin -GO Base utiL ImplementatioN diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..7aa9e0d --- /dev/null +++ b/README.txt @@ -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. diff --git a/newnix/echo/main.go b/echo/main.go similarity index 100% rename from newnix/echo/main.go rename to echo/main.go diff --git a/mkdir/main.go b/mkdir/main.go new file mode 100644 index 0000000..a523442 --- /dev/null +++ b/mkdir/main.go @@ -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) + } + } +} diff --git a/newnix/README.txt b/newnix/README.txt deleted file mode 100644 index 86a7c2d..0000000 --- a/newnix/README.txt +++ /dev/null @@ -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.