cli icon indicating copy to clipboard operation
cli copied to clipboard

Required flag breaks completion generation

Open jurisevo opened this issue 1 month ago • 0 comments

Dear developers,

My urfave/cli version is

( v3.6.1 )

Checklist

  • [x] Are you running the latest v3 release? The list of releases is here.
  • [x] Did you check the manual for your release? The v3 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

Specifying a required flag breaks shell completion generation.

To reproduce

With greet defined as below with required dummy flag and EnableShellCompletion: true:

package main

import (
	"context"
	"fmt"
	"log"
	"os"

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

func main() {
	cmd := &cli.Command{
		Name:                  "greet",
		Usage:                 "fight the loneliness!",
		EnableShellCompletion: true,

		Flags: []cli.Flag{
			&cli.StringFlag{
				Name:     "dummy",
				Usage:    "dummy required flag",
				Required: true,
			},
			&cli.BoolFlag{
				Name:    "debug",
				Aliases: []string{"d"},
				Usage:   "debug flag",
				Value:   false,
			},
		},
		Action: func(context.Context, *cli.Command) error {
			fmt.Println("Hello friend!")
			return nil
		},
	}

	if err := cmd.Run(context.Background(), os.Args); err != nil {
		log.Fatal(err)
	}
}

Observed behavior

When running greet completion bash I get following otuput:

$ ./greet completion bash
NAME:
   greet completion - Output shell completion script for bash, zsh, fish, or Powershell

USAGE:
   greet completion

DESCRIPTION:
   Output shell completion script for bash, zsh, fish, or Powershell.
   Source the output to enable completion.

   # .bashrc
   source <(greet completion bash)

   # .zshrc
   source <(greet completion zsh)

   # fish
   greet completion fish > ~/.config/fish/completions/greet.fish

   # Powershell
   Output the script to path/to/autocomplete/greet.ps1 an run it.


OPTIONS:
   --help, -h  show help
2025/11/30 20:34:36 Required flag "dummy" not set

Expected behavior

I was expecting that generating of shell completion is not dependant on required flags. The observed behaviour is not documented as well.

Run go version and paste its output here

go version go1.25.4 darwin/arm64

jurisevo avatar Nov 30 '25 18:11 jurisevo