feat: simplify flag parsing in buildpacks plugin
Commands should be written such that they take arguments as is.
This commit is contained in:
@@ -21,30 +21,39 @@ func main() {
|
||||
args := flag.NewFlagSet("buildpacks:add", flag.ExitOnError)
|
||||
index := args.Int("index", 0, "--index: the 1-based index of the URL in the list of URLs")
|
||||
args.Parse(os.Args[2:])
|
||||
err = buildpacks.CommandAdd(args.Args(), *index)
|
||||
appName := args.Arg(0)
|
||||
buildpack := args.Arg(1)
|
||||
err = buildpacks.CommandAdd(appName, buildpack, *index)
|
||||
case "clear":
|
||||
args := flag.NewFlagSet("buildpacks:clear", flag.ExitOnError)
|
||||
args.Parse(os.Args[2:])
|
||||
err = buildpacks.CommandClear(args.Args())
|
||||
appName := args.Arg(0)
|
||||
err = buildpacks.CommandClear(appName)
|
||||
case "list":
|
||||
args := flag.NewFlagSet("buildpacks:list", flag.ExitOnError)
|
||||
args.Parse(os.Args[2:])
|
||||
buildpacks.CommandList(args.Args())
|
||||
appName := args.Arg(0)
|
||||
err = buildpacks.CommandList(appName)
|
||||
case "remove":
|
||||
args := flag.NewFlagSet("buildpacks:remove", flag.ExitOnError)
|
||||
index := args.Int("index", 0, "--index: the 1-based index of the URL in the list of URLs")
|
||||
args.Parse(os.Args[2:])
|
||||
err = buildpacks.CommandRemove(args.Args(), *index)
|
||||
appName := args.Arg(0)
|
||||
buildpack := args.Arg(1)
|
||||
err = buildpacks.CommandRemove(appName, buildpack, *index)
|
||||
case "report":
|
||||
flag.Parse()
|
||||
appName := flag.Arg(1)
|
||||
infoFlag := flag.Arg(2)
|
||||
buildpacks.CommandReport(appName, infoFlag)
|
||||
args := flag.NewFlagSet("buildpacks:report", flag.ExitOnError)
|
||||
args.Parse(os.Args[2:])
|
||||
appName := args.Arg(0)
|
||||
infoFlag := args.Arg(1)
|
||||
err = buildpacks.CommandReport(appName, infoFlag)
|
||||
case "set":
|
||||
args := flag.NewFlagSet("buildpacks:set", flag.ExitOnError)
|
||||
index := args.Int("index", 0, "--index: the 1-based index of the URL in the list of URLs")
|
||||
args.Parse(os.Args[2:])
|
||||
err = buildpacks.CommandSet(args.Args(), *index)
|
||||
appName := args.Arg(0)
|
||||
buildpack := args.Arg(1)
|
||||
err = buildpacks.CommandSet(appName, buildpack, *index)
|
||||
default:
|
||||
common.LogFail(fmt.Sprintf("Invalid plugin subcommand call: %s", subcommand))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user