cli icon indicating copy to clipboard operation
cli copied to clipboard

Flag-level Action

Open xwjdsh opened this issue 3 years ago • 12 comments

What type of PR is this?

  • feature

What this PR does / why we need it:

https://github.com/urfave/cli/issues/1219 I like the idea, but there is no comment from the maintainers, I'd like to have a simple implementation first and then hear your opinions.

Example

package main

import (
	"fmt"
	"os"

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

func main() {
	app := &cli.App{
		Action: func(c *cli.Context) error { return nil },
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name: "f",
				Action: func(c *cli.Context, s string) error {
					fmt.Println(s)
					return nil
				},
			},
		},
	}

	err := app.Run(os.Args)
	if err != nil {
		panic(err)
	}
}
## nothing if no flag
go run main.go
## print flag value
go run main.go -f test
#> test

Which issue(s) this PR fixes:

close https://github.com/urfave/cli/issues/1219

xwjdsh avatar Feb 15 '22 16:02 xwjdsh

@dearchap Thank you for your review, I updated and rebased main branch.

xwjdsh avatar Apr 30 '22 16:04 xwjdsh

Ack, sorry for the conflicts! I'm happy to attempt to resolve them.

meatballhat avatar May 01 '22 00:05 meatballhat

~These conflicts are going to be more difficult given the flag generation code introduced in the meantime. Giving it a shot 🤞🏼~

The conflicts were straightforward, but follow-up changes will be needed to re-add the Action field to every struct 😭

meatballhat avatar May 07 '22 12:05 meatballhat

@meatballhat I'll fix it later, that's OK.

xwjdsh avatar May 07 '22 13:05 xwjdsh

@xwjdsh I'm happy to carry this work forward if you're not able ❤️

meatballhat avatar May 22 '22 12:05 meatballhat

Sorry for being late, I updated.

Update gopkg.in/yaml.v2 to gopkg.in/yaml.v3 cause v2 seems have an issue that commas cannot be unmarshal correctly, I switched to v3 and the issue resolved.

xwjdsh avatar May 22 '22 15:05 xwjdsh

@xwjdsh I'm sorry about this frustrating feedback loop with having to approve GitHub Actions 😩

meatballhat avatar May 22 '22 18:05 meatballhat

@meatballhat I'm a little bit confused about the CI error, my local environment is normal...

xwjdsh avatar May 24 '22 10:05 xwjdsh

@xwjdsh I'm sorry about this. There's something up with the way that the go.mod is written that seems to be upsetting for go 1.16.x. This isn't the first time this problem has come up in CI. Here's my attempted fix: https://github.com/urfave/cli/pull/1407. Once that's merged, can you incorporate latest main?

meatballhat avatar May 24 '22 12:05 meatballhat

@xwjdsh @meatballhat Is one of you looking at the test failures and conflicts ?

dearchap avatar Sep 10 '22 20:09 dearchap

@xwjdsh @meatballhat Is one of you looking at the test failures and conflicts ?

Not me!

meatballhat avatar Sep 10 '22 23:09 meatballhat

@dearchap It's OK now.

xwjdsh avatar Sep 15 '22 15:09 xwjdsh