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:
parent
29d369f5ae
commit
97c9e0d14f
35
cmd/cdr/clean.go
Normal file
35
cmd/cdr/clean.go
Normal 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
|
||||||
|
}
|
@ -1,37 +1,27 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"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() {
|
func main() {
|
||||||
flag.Usage = printUsage
|
app := &cli.App{
|
||||||
flag.Parse()
|
Name: "CD-R 700MB",
|
||||||
|
Usage: "A static mixtape site generator",
|
||||||
wd, err := os.Getwd()
|
Version: "v1.0",
|
||||||
if err != nil {
|
Flags: []cli.Flag{},
|
||||||
log.Fatal(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
|
app.Commands = []*cli.Command{
|
||||||
})
|
&cmdClean,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := app.Run(os.Args)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user