Skip to content

Using comma in flag name for alternatives breaks #1142

Description

@erikwilson

my urfave/cli version is

v1.22.4

Checklist

  • Are you running the latest v1 release? The list of releases is here.
  • Did you check the manual for your release? The v1 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.
  • My project is using vendoring.

Describe the bug

When using alternates in flag names altsrc does not copy the flag value.

To reproduce

package main

import (
  "fmt"
  "log"
  "os"

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

var (
  test int
)

func main() {
  app := cli.NewApp()

  flags := []cli.Flag{
    altsrc.NewIntFlag(cli.IntFlag{Name: "test,t", Destination: &test}),
    cli.StringFlag{Name: "load"},
  }

  app.Action = func(c *cli.Context) error {
    fmt.Printf("Have test value: %d\n", test)
    return nil
  }

  app.Before = altsrc.InitInputSourceWithContext(flags, altsrc.NewYamlSourceFromFlagFunc("load"))
  app.Flags = flags

  err := app.Run(os.Args)
  if err != nil {
    log.Fatal(err)
  }
}
echo test: 1 >conf
GO111MODULE=on go run test.go --load conf

Observed behavior

Have test value: 0

Expected behavior

Have test value: 1

Additional context

Previously reported in #711

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/v1relates to / is being considered for v1help wantedplease help if you can!kind/bugdescribes or fixes a bug

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions