I am using urfave/cli to build a CLI application in Go.
What I would like is options given after the first command to be treated as arguments and not flags (so that I can handle them myself or pass them to an other executable).
When using app.Action
(see below), this is the behavior that I get, but if I am using cli.Commands
then I get an error.
package main
import (
"fmt"
"github.com/urfave/cli"
"log"
"os"
)
func main() {
app := cli.NewApp()
app.Commands = []cli.Command{
{
Name: "test",
Action: func(c *cli.Context) error {
fmt.Println("test", c.Args())
return nil
},
},
}
app.Action = func(c *cli.Context) error {
fmt.Println(c.Args())
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
Output of: go run main.go cmd -f flag
:
[cmd -f flag]
but go run main.go test cmd -f flag
exits with an error where I would like it to oupput
test [cmd -f flag]