Skip to content

BoolFlag Count and/or compound not working  #1942

@native0090

Description

@native0090

My urfave/cli version is

v2.27.2

Dependency Management

  • My project is using go modules.

Describe the bug

The v2 documentation states:

For bool flags you can specify the flag multiple times to get a count(e.g -v -v -v or -vvv)

It seems that you can specify the flag multiple times with -v -v -v but not with -vvv.

To reproduce

Minimal example to reproduce:

package main

import (
	"fmt"
	"log"
	"os"

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

func main() {
	var count int

	app := &cli.App{
		Flags: []cli.Flag{
			&cli.BoolFlag{
				Name:    "verbosity",
				Aliases: []string{"v"},
				Count:   &count,
			},
		},
		Action: func(cCtx *cli.Context) error {
			fmt.Println("count", count)
			return nil
		},
	}

	if err := app.Run(os.Args); err != nil {
		log.Fatal(err)
	}
}

Observed behavior

Running this program without parameters works as expected.
Running with -v works as expected.
Running with -v -v works as expected.
Running with -vv does not work as expected and prints following message:

2024/07/01 12:17:32 flag provided but not defined: -vv

Run go version and paste its output here

go version go1.22.4 linux/amd64

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/v2relates to / is being considered for v2kind/bugdescribes or fixes a bugstatus/triagemaintainers still need to look into this

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions