-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Use of obsolete v1 aliases goes undetected #1103
Comments
@TomOnTime can you add a title to the issue? |
This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else. |
Closing this as it has become stale. |
This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant. |
This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else. |
Closing this as it has become stale. |
From what I can tell, at the time of Lines 262 to 274 in 6033c00
Given that we don't really have a compile-time or type-enforced way of preventing |
It's not that difficult but I think the framework should report such low-level mistakes to developers. Without framework support, I have to do: func reflectGet(v any, fieldName string) any {
e := reflect.ValueOf(v).Elem()
return e.FieldByName(fieldName).Interface()
}
// https://cli.urfave.org/migrate-v1-to-v2/#flag-aliases-are-done-differently
// Sadly v2 doesn't warn you if a comma is in the name. (https://github.com/urfave/cli/issues/1103)
func checkCommandFlags(c any) bool {
var cmds []*cli.Command
if app, ok := c.(*cli.App); ok {
cmds = app.Commands
} else {
cmds = c.(*cli.Command).Subcommands
}
ok := true
for _, cmd := range cmds {
for _, flag := range cmd.Flags {
flagName := reflectGet(flag, "Name").(string)
if strings.Contains(flagName, ",") {
ok = false
log.Error("cli.Flag can't have comma in its Name: %q, use Aliases instead", flagName)
}
}
if !checkCommandFlags(cmd) {
ok = false
}
}
return ok
} |
my urfave/cli version is
2.2.0
Checklist
Dependency Management
Describe the bug
There is no warning if old-style v1 aliases are used. The alias simply doesn't exist.
To reproduce
Create a flag using the v1 method:
Observed behavior
The flag --config works; --cfg does not.
Expected behavior
The system should output an error or warning.
Additional context
Ideally if
Name
includes a space or a comma, the code should output anmessage about "Old style alias being used. Please see docs/migrate-v1-to-v2.md"
then the program should exit.
Want to fix this yourself?
no
Run
go version
and paste its output hereRun
go env
and paste its output hereThe text was updated successfully, but these errors were encountered: