1
0
mirror of https://github.com/thebaer/cdr.git synced 2024-11-15 01:31:01 +00:00

Move work to clean subcommand

This commit is contained in:
Matt Baer 2020-02-25 22:53:11 -05:00
parent 29d369f5ae
commit 97c9e0d14f
2 changed files with 50 additions and 25 deletions

35
cmd/cdr/clean.go Normal file
View File

@ -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
}

View File

@ -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()
app := &cli.App{
Name: "CD-R 700MB",
Usage: "A static mixtape site generator",
Version: "v1.0",
Flags: []cli.Flag{},
}
wd, err := os.Getwd()
app.Commands = []*cli.Command{
&cmdClean,
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
log.Println(err.Error())
os.Exit(1)
}
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
})
}