diff --git a/cmd/cdr/clean.go b/cmd/cdr/clean.go new file mode 100644 index 0000000..65251b5 --- /dev/null +++ b/cmd/cdr/clean.go @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "os" + "path/filepath" + "strings" + + "github.com/thebaer/cdr" + "github.com/urfave/cli" +) + +var cmdClean = cli.Command{ + Name: "clean", + Usage: "clean and organize files", + Action: cleanAction, +} + +func cleanAction(c *cli.Context) error { + wd, err := os.Getwd() + if err != nil { + return err + } + filepath.Walk(wd, func(path string, i os.FileInfo, err error) error { + if !i.IsDir() && !strings.HasPrefix(i.Name(), ".") { + fName := i.Name() + trackName := cdr.RenameTrack(fName) + fmt.Println("Renaming", fName, "to", trackName) + os.Rename(fName, trackName) + } + + return nil + }) + return nil +} diff --git a/cmd/cdr/main.go b/cmd/cdr/main.go index a6cbd99..2d50c7f 100644 --- a/cmd/cdr/main.go +++ b/cmd/cdr/main.go @@ -1,37 +1,27 @@ package main import ( - "flag" - "fmt" "log" "os" - "path/filepath" - "strings" - "github.com/thebaer/cdr" + "github.com/urfave/cli" ) -var printUsage = func() { - fmt.Fprintf(os.Stderr, "usage: %s [optional flags] filename\n", os.Args[0]) - flag.PrintDefaults() -} - func main() { - flag.Usage = printUsage - flag.Parse() - - wd, err := os.Getwd() - if err != nil { - log.Fatal(err) + app := &cli.App{ + Name: "CD-R 700MB", + Usage: "A static mixtape site generator", + Version: "v1.0", + Flags: []cli.Flag{}, } - filepath.Walk(wd, func(path string, i os.FileInfo, err error) error { - if !i.IsDir() && !strings.HasPrefix(i.Name(), ".") { - fName := i.Name() - trackName := cdr.RenameTrack(fName) - fmt.Println("Renaming", fName, "to", trackName) - os.Rename(fName, trackName) - } - return nil - }) + app.Commands = []*cli.Command{ + &cmdClean, + } + + err := app.Run(os.Args) + if err != nil { + log.Println(err.Error()) + os.Exit(1) + } }