Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds urfave/cli/v2 flag parser #330

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joicemjoseph
Copy link

No description provided.

@joicemjoseph joicemjoseph changed the title adds urfafe/cli/v2 flag parser adds urfave/cli/v2 flag parser Oct 17, 2024
@joicemjoseph joicemjoseph marked this pull request as draft October 17, 2024 11:05
Copy link

@YvanDaSilva YvanDaSilva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firstly, Great work!
I was going to create an issue to support urfave/cli I'm very glad I didn't and looked at PR's first.

I am currently using v3, I left a few comments here, let me know your opinion.
If you want to stay with v2, I will gladly make a PR for v3, but I suggest you also version this one so they can both live on the same repo under the same name :)

"strings"

"github.com/knadh/koanf/maps"
"github.com/urfave/cli/v2"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v3 is on the verge of being released:

It may well be worth it to either version this provider behind /v2 or jump to /v3 right away.


// CliFlag implements a cli.Flag command line provider.
type CliFlag struct {
ctx *cli.Context

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v3 will help to remove this custom context and rely on context.Context instead.

https://github.com/urfave/cli/tree/main/docs/v3

migration: https://github.com/urfave/cli/blob/main/docs/migrate-v2-to-v3.md#clicontext-has-been-removed

It also makes a much saner API for all the methods below.
Passing the cli.Command could also result in a less opinionated way of parsing flags in koanf.

Comment on lines +44 to +47
cmdPath = append(cmdPath, cmd.Command.Name)
prefix := strings.Join(cmdPath, p.delim)
p.processFlags(cmd.Command.Flags, prefix, out)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the user should provide flag to key mappings.
This leads to an opinionated way to create the returned map keys.
I understand the intention to travel all the command and parse all flags but maybe that is not what any user would want.

I have looked into urfave/cli to see if there is a way to indicate which flags will be used as config and which aren't, but there isn't a way for this. So maybe there is a way to let user of Koanf the ability to say which flags are or aren't to be handled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants