cli
cli copied to clipboard
Flag-level Action
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
@dearchap Thank you for your review, I updated and rebased main branch.
Ack, sorry for the conflicts! I'm happy to attempt to resolve them.
~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 I'll fix it later, that's OK.
@xwjdsh I'm happy to carry this work forward if you're not able ❤️
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 I'm sorry about this frustrating feedback loop with having to approve GitHub Actions 😩
@meatballhat I'm a little bit confused about the CI error, my local environment is normal...
@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?
@xwjdsh @meatballhat Is one of you looking at the test failures and conflicts ?
@xwjdsh @meatballhat Is one of you looking at the test failures and conflicts ?
Not me!
@dearchap It's OK now.