github.com/rck/u-root@v0.0.0-20180106144920-7eb602e381bb/cmds/mkdir/mkdir.go (about) 1 // Copyright 2012-2017 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Mkdir makes a new directory. 6 // 7 // Synopsis: 8 // mkdir [-m mode] [-v] [-p] DIRECTORY... 9 // 10 // Options: 11 // -m: make all needed directories in the path 12 // -v: directory mode (ex: 666) 13 // -p: print each directory as it is made 14 package main 15 16 import ( 17 "flag" 18 "fmt" 19 "os" 20 ) 21 22 var ( 23 mkall = flag.Bool("p", false, "Make all needed directories in the path") 24 mode = flag.Int("m", 0666, "Directory mode") 25 verbose = flag.Bool("v", false, "Print each directory as it is made") 26 f = os.Mkdir 27 ) 28 29 func main() { 30 flag.Parse() 31 if len(flag.Args()) < 1 { 32 fmt.Printf("Usage: mkdir [-m mode] [-v] [-p] <directory> [more directories]\n") 33 os.Exit(1) 34 } 35 if *mkall { 36 f = os.MkdirAll 37 } 38 for _, name := range flag.Args() { 39 if err := f(name, os.FileMode(*mode)); err != nil { 40 fmt.Printf("%v: %v\n", name, err) 41 } else { 42 if *verbose { 43 fmt.Printf("%v\n", name) 44 } 45 } 46 } 47 }