-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
add generated completions for shells #34973
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
base: main
Are you sure you want to change the base?
Conversation
since flags aren't marked as local they cascade through the app so before can be used as setup as we need to define flags once.
only main and it's subcommands are directly handled by it
instead of looping though the flags in linage, use their non local property
add fish to docs
cmd/main.go
Outdated
for i := range command.Commands { | ||
prepareSubcommandWithGlobalFlags(command.Commands[i]) | ||
} | ||
command.Before = prepareWorkPathAndCustomConf() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in short: Yes.
for background context - flags are persistent in v3 by default meaning if you define a flag at (gitea) level, then the (gitea actions) command also has it. To opt out of this you have to mark the flag as local
in it's definition.
This doesn't matter for flags which are attached to final command of course as the flag has nowhere to propagate to.
Removing the loop removes the cascading issue so the setup is done only once and flags still propagate (as they aren't marked as local). This can be verified by adding a print in the function and running any nested command.
But this made me catch that i'm overwriting the original before function which I've patched just now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, it seems that there is a changed behavior in v3 (so: yes 👍)
Will take a deep look soon.
By the way, another question: what does TakesFile: true
do? Why we only set it for these 3 global args but not for others?
diff --git a/cmd/main.go b/cmd/main.go
index 49252f0046..05639906b4 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -67,6 +67,7 @@ func prepareWorkPathAndCustomConf(original cli.BeforeFunc) cli.BeforeFunc {
if cmd.IsSet("config") {
args.CustomConf = cmd.String("config")
}
+ println("InitWorkPathAndCommonConfig", "cmd="+cmd.Name, "config="+args.CustomConf)
setting.InitWorkPathAndCommonConfig(os.Getenv, args)
return original(ctx, cmd)
}
~/work/gitea$ ./gitea -c /dev/null admin user create --name test1 --email [email protected]
InitWorkPathAndCommonConfig cmd=admin config=/dev/null
~/work/gitea$ ./gitea admin user create -c /dev/null --name test1 --email [email protected]
InitWorkPathAndCommonConfig cmd=admin config=/dev/null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TakesFile is a hint for shell complete that the flag takes file. It should be added to every flag which does that so the completion will list files. It's not a high priority thing, I just added them since I'm reworking those flags, but I can add them to other ones in this PR to have it cleared off the list.
add makefile rule for shell completions, disable internal commands from showing in help
rework custom help so it only triggers on first level commands
help changes are mainly to work around regression: #34510 (comment)