-
Notifications
You must be signed in to change notification settings - Fork 8
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
Specific account names can lead to the wrong error occuring #147
Comments
So what happens is that CommandWithoutConfig only checks if any argument is |
Problems could also arise when renaming the executable to one of the mentioned names, as os.Args[0] is the program name |
Indeed. CommandWithoutConfig is called with os.Args everywhere. It's not a good implementation. A better way would be to check the current Cobra sub-command name if it's in that list instead of reading os.Args. |
But Cobra only let's you check if there's a sub-command afaik |
This works but isn't really well maintainable |
you can do |
I believe the sub-command's name is always the 1st string in the list without the flag notation |
btw, flags can be shorthand flags |
So func CommandWithoutConfig(cmdLine []string) bool {
var noConfigNeeded = []string{
"make-config", "version", "manpage", "completion",
}
for _, arg := range cmdLine {
if !strings.HasPrefix(arg, "-") {
// do the check and break the loop.
}
}
return false
} |
Flags can have different notations like |
I think this can be done with |
Hi. You can use PersistentPreRunE to check & load the configuration only when needed similar to this code fragment:
A
The check would be this:
|
This is a major redesign though and would need rather extensive testing... If there's an easier way to modify the current approach I'd prefer that |
So I found out, that renaming This only has the problem that no sub-command can have further sub-commands called |
When you call
gscloud server create --account make-config --name testName --cores 1 --mem 1
, it doesn't matter if there's an accountmake-config
in the config file, and the program just attempts to create a server which will fails due to no authorization, because the account doesn't exist and no UUID/token were loadedThe other account names this applies to are
version
,manpage
andcompletion
Similar thing happens with
gscloud server create --name completion --cores 1 --mem 1
when no config exists, andcompletion
may be a name you want to give your serverExpected result would be this error
account 'make-config' does not exist
The text was updated successfully, but these errors were encountered: