Specify a default value for -directory param

This is done through use of flag.String instead of flag.StringVar
This commit is contained in:
Fred Pauchet 2022-09-16 19:37:19 +02:00
parent 4707d458c4
commit 1724b9664c
1 changed files with 3 additions and 3 deletions

6
main.go Normal file → Executable file
View File

@ -29,16 +29,16 @@ func walk(rootDir string) ([]string, error) {
func main() {
var rootDir string
var rootDir *string
flag.StringVar(&rootDir, "d", "directory", "Specify the directory to parse.")
rootDir = flag.String("dir", ".", "Specify the directory to parse.")
flag.Usage = func() {
fmt.Printf("Jack expects: \n")
fmt.Printf("./jack -d <rootDir>\n")
}
flag.Parse()
files, _ := walk(rootDir)
files, _ := walk(*rootDir)
for _, file := range files {
fmt.Println(file)