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
|
var execCmd string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
args := os.Args[1:]
|
flag.BoolVar(&dryrun, "n", false, "Show what would have been done.")
|
||||||
if len(args) == 0 {
|
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")
|
fmt.Println("No action specified")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
flag.BoolVar(&dryrun, "n", false, "Show what would have been done.")
|
if !dryrun {
|
||||||
flag.StringVar(&execCmd, "exec", "", "Run command on matching file.")
|
panic("please dry run first")
|
||||||
path := flag.String("path", "p", "Handle files in path.")
|
}
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
switch flag.Arg(0) {
|
switch flag.Arg(0) {
|
||||||
case "normalize":
|
case "normalize":
|
||||||
@ -36,7 +39,7 @@ func main() {
|
|||||||
case "removesuffix":
|
case "removesuffix":
|
||||||
fallthrough
|
fallthrough
|
||||||
case "rs":
|
case "rs":
|
||||||
suffix := args[1]
|
suffix := flag.Arg(1)
|
||||||
err := filepath.Walk(*path, removeSuffix(suffix))
|
err := filepath.Walk(*path, removeSuffix(suffix))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user