cli icon indicating copy to clipboard operation
cli copied to clipboard

Could support the SkipFlagParsing is true with flags?

Open x2c3z4 opened this issue 3 years ago • 4 comments

Could support the SkipFlagParsing is true with flags?

For example:

package main

import (
        "fmt"
        "os"

        "github.com/urfave/cli"
)

func main() {
        app := cli.NewApp()
        var uuid cli.StringSlice
        app.Commands = []cli.Command{
                {
                        Name:  "test",
                        Usage: "cli testing",
                        Flags: []cli.Flag{
                                cli.StringSliceFlag{Name: "uuid", Value: &uuid},
                        },
                        Action: func(c *cli.Context) {
                                fmt.Fprintf(os.Stdout, "uuid: %v\n", uuid)
                                for _, x := range c.Args() {
                                        fmt.Fprintln(os.Stdout, x)
                                }
                        },
                        SkipFlagParsing: false,
                },
        }
        app.Run(os.Args)
}

It outputs:

 go run test2.go test -uuid foobar -a a
Incorrect Usage: flag provided but not defined: -a

NAME:
   test2 test - cli testing

USAGE:
   test2 test [command options] [arguments...]

OPTIONS:
   --uuid value  (default: "foobar")

Expect:

uuid: [foobar]
-a
a

x2c3z4 avatar Feb 25 '21 08:02 x2c3z4

+1 need that

fengqi avatar May 13 '21 04:05 fengqi

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

stale[bot] avatar Aug 18 '21 01:08 stale[bot]

+1

xyb avatar Aug 18 '21 12:08 xyb

This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant.

stale[bot] avatar Aug 18 '21 12:08 stale[bot]

In general we cant have it both ways, if SkipFlagParsing is false the behaviour is as expected. If SkipFlagParsing is set to true then output is

uuid: []
--uuid
dd
--a
a

dearchap avatar Oct 23 '22 23:10 dearchap