Skip to content

Flag Action not invoked when the value is supplied from ENV Sources #2132

@nicfit

Description

@nicfit

My urfave/cli version is

3.3.3

Checklist

  • Are you running the latest v3 release? The list of releases is here.
  • Did you check the manual for your release? The v3 manual is here
  • 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 program cli-flag-action invokes the Flag Action function when an option is given, but not when the option comes from an EnvVars source.

➜ cli-flag-action --config=flag.yml
Flag Action: flag.yml
Config: flag.yml

➜ CONFIG=env.yml cli-flag-action
Config: env.yml

The program:

package main

import (
	"context"
	"fmt"
	"github.com/urfave/cli/v3"
	"os"
)

func main() {
	cmd := &cli.Command{
		Action: func(ctx context.Context, command *cli.Command) error {
			fmt.Println("Config:", command.String("config"))
			return nil
		},
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name:     "config",
				Usage:    "Configuration file",
				Required: false,
				Sources:  cli.EnvVars("CONFIG"),
				Action: func(ctx context.Context, command *cli.Command, s string) error {
					fmt.Println("Flag Action:", s)
					return nil
				},
			},
		},
	}

	cmd.Run(context.Background(), os.Args)
}

To reproduce

See above.

Observed behavior

Flag action not called for environment sources.

Expected behavior

Flag Action invoked regardless of value source.

Additional context

n/a

Want to fix this yourself?

Perhaps, if my expectations are confirmed.

Run go version and paste its output here

go version go1.23.1 linux/amd64

Run go env and paste its output here

# paste `go env` output in here

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/v3relates to / is being considered for v3kind/bugdescribes or fixes a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions