fix: use flag args instead of os.Args directly
This commit is contained in:
parent
fccbbc723d
commit
94ca2169a2
17
main.go
17
main.go
@ -14,16 +14,19 @@ var dryrun bool
|
||||
var execCmd string
|
||||
|
||||
func main() {
|
||||
args := os.Args[1:]
|
||||
if len(args) == 0 {
|
||||
flag.BoolVar(&dryrun, "n", false, "Show what would have been done.")
|
||||
flag.StringVar(&execCmd, "exec", "", "Run command on matching file.")
|
||||
path := flag.String("path", ".", "Handle files in path.")
|
||||
flag.Parse()
|
||||
|
||||
if flag.NArg() == 0 {
|
||||
fmt.Println("No action specified")
|
||||
return
|
||||
}
|
||||
|
||||
flag.BoolVar(&dryrun, "n", false, "Show what would have been done.")
|
||||
flag.StringVar(&execCmd, "exec", "", "Run command on matching file.")
|
||||
path := flag.String("path", "p", "Handle files in path.")
|
||||
flag.Parse()
|
||||
if !dryrun {
|
||||
panic("please dry run first")
|
||||
}
|
||||
|
||||
switch flag.Arg(0) {
|
||||
case "normalize":
|
||||
@ -36,7 +39,7 @@ func main() {
|
||||
case "removesuffix":
|
||||
fallthrough
|
||||
case "rs":
|
||||
suffix := args[1]
|
||||
suffix := flag.Arg(1)
|
||||
err := filepath.Walk(*path, removeSuffix(suffix))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user