cli icon indicating copy to clipboard operation
cli copied to clipboard

SkipFlagParsing is not working if there are Subcommands

Open Or-Geva opened this issue 2 years ago • 5 comments

my urfave/cli version is

v1.22.5

Checklist

  • [x] Are you running the latest v1 release? The list of releases is here.
  • [x] Did you check the manual for your release? The v1 manual is here
  • [x] Did you perform a search about this problem? Here's the Github guide about searching.

Dependency Management

  • My project is using go modules.

Describe the bug

The options of SkipFlagParsing: true and CustomHelpTemplate:"..." are not working if there are Subcommands.

To reproduce

package main

import (
	"fmt"
	"os"

	"github.com/urfave/cli"
)

func main() {
	app := cli.NewApp()
	app.Name = "foo"
	app.Commands = []cli.Command{
		{
			Name:            "bar",
			SkipFlagParsing: true,
			Action: func(c *cli.Context) {
				fmt.Println(c.Args())
			},
			Subcommands: []cli.Command{{

				Name:            "barfoo",
				SkipFlagParsing: true,
				Action: func(c *cli.Context) {
					fmt.Println(c.Args())
				},
			},
			},
		},
	}

	app.Run(os.Args)
}

Observed behavior

Run:

go build  -o skip && ./skip bar --a  

Observed behavior:

Incorrect Usage. flag provided but not defined: -a

NAME:
   foo bar - 

USAGE:
   foo bar command [command options] [arguments...]

COMMANDS:
   barfoo  

OPTIONS:
   --help, -h  show help

Expected behavior

The output should be:

[--a]

Additional context

It works if I remove:

	Subcommands: []cli.Command{{

		Name:            "barfoo",
		SkipFlagParsing: true,
		Action: func(c *cli.Context) {
			fmt.Println(c.Args())
		},
	},
	},

Or-Geva avatar Feb 20 '22 13:02 Or-Geva

@meatballhat I can take a look at this

dearchap avatar Apr 24 '22 19:04 dearchap

@dearchap thank you much!

meatballhat avatar Apr 24 '22 20:04 meatballhat

@meatballhat Are we still fixing v1 issues ? I verified that this issue doesnt exist in v2.

dearchap avatar Apr 25 '22 00:04 dearchap

@dearchap I'd love to know 😅 I asked a question a few days ago in @urfave/maintainers discussions but I've re-posted now in @urfave/cli discussions. If having this conversation in a public issue is acceptable, I'll gladly go that route instead.

meatballhat avatar Apr 25 '22 00:04 meatballhat

@Or-Geva By definition you should not use subcommands when you set skip flag parsing

dearchap avatar Apr 25 '22 00:04 dearchap