Skip to content

Unknown flag parsing is broken from v2 #2072

@MrNaif2018

Description

@MrNaif2018

Hi! Using the latest released urfave/cli v3.0.0-beta1, I get a different behaviour from v2

V2:

alex@alex-mac testcli % ./testcli -w test command arg1 arg2 --arg3 true --arg4 false
&[command arg1 arg2 --arg3 true --arg4 false]
alex@alex-mac testcli % ./testcli -w test command arg1 arg2 -- --arg3 true --arg4 false
&[command arg1 arg2 -- --arg3 true --arg4 false]

V3:

alex@alex-mac testcli % ./testcli -w test command arg1 arg2 --arg3 true --arg4 false
Incorrect Usage: flag provided but not defined: -arg3

flag provided but not defined: -arg3
alex@alex-mac testcli % ./testcli -w test command arg1 arg2 -- --arg3 true --arg4 false
&{[command arg1 arg2 -- --arg3 true --arg4 false]}

I rely on unknown flags parsing to parse all by-name arguments to external JSONRPC server. There's SkipFlagParsing but it seems to disable all functionality in general
Is there some way to allow to parse unknown flags in Action still?

Attaching example code to test in V2 and V3

V2 code
package main

import (
	"fmt"
	"os"

	"github.com/urfave/cli/v2"
)

func main() {
	app := cli.NewApp()
	app.Name = "testcli"
	app.Version = "1.0.0"
	app.HideHelp = true
	app.Usage = "Call RPC methods from console"
	app.UsageText = "testcli method [args]"
	app.EnableBashCompletion = true
	app.Flags = []cli.Flag{
		&cli.BoolFlag{
			Name:    "help",
			Aliases: []string{"h"},
			Usage:   "show help",
		},
		&cli.StringFlag{
			Name:     "wallet",
			Aliases:  []string{"w"},
			Usage:    "specify wallet",
			Required: false,
		},
	}
	app.Action = func(c *cli.Context) error {
		args := c.Args()
		fmt.Println(args)
		return nil
	}
	if err := app.Run(os.Args); err != nil {
		fmt.Println(err)
	}
}
V3 code
package main

import (
	"context"
	"fmt"
	"os"

	"github.com/urfave/cli/v3"
)

func main() {
	app := &cli.Command{
		Name:                  "testcli",
		Version:               "1.0.0",
		HideHelp:              true,
		Usage:                 "Call RPC methods from console",
		UsageText:             "testcli method [args]",
		EnableShellCompletion: true,
		Flags: []cli.Flag{
			&cli.BoolFlag{
				Name:    "help",
				Aliases: []string{"h"},
				Usage:   "show help",
			},
			&cli.StringFlag{
				Name:     "wallet",
				Aliases:  []string{"w"},
				Usage:    "specify wallet",
				Required: false,
			},
		},
		Action: func(ctx context.Context, cmd *cli.Command) error {
			fmt.Println(cmd.Args())
			return nil
		},
	}
	if err := app.Run(context.Background(), os.Args); err != nil {
		fmt.Println(err)
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/v3relates to / is being considered for v3kind/bugdescribes or fixes a bugstatus/waiting-for-responseWaiting for response from original requester

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions