Read parameter from CLI and list files.

See
*
f72131f1be
This commit is contained in:
Fred 2020-10-06 20:37:07 +02:00
parent 9a56e4dffa
commit 510c4ef49f
2 changed files with 51 additions and 2 deletions

41
main.go
View File

@ -1,7 +1,44 @@
package main
import "fmt"
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
)
func walk(rootDir string) {
err := filepath.Walk(rootDir,
func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
dir, file := filepath.Split(path)
ext := filepath.Ext(file)
if ext == ".md" {
fmt.Println(dir, file, ext, info.Size())
}
return nil
})
if err != nil {
log.Println(err)
}
}
func main() {
fmt.Println("Hi, I'm Jack!")
var rootDir string
flag.StringVar(&rootDir, "d", "directory", "Specify the directory to parse.")
flag.Usage = func() {
fmt.Printf("Jack expects: \n")
fmt.Printf("./jack -d <rootDir>\n")
}
flag.Parse()
walk(rootDir)
}

12
main_test.go Normal file
View File

@ -0,0 +1,12 @@
package main
import "testing"
func TestSayHi(t *testing.T) {
expected := "Hi, I'm Jack"
greeting := sayHi()
if greeting != expected {
t.Errorf("Greeting was incorrect, got: '%s', want: '%s'", greeting, expected)
}
}