Skip to content

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

TheFox0x7
Copy link
Contributor

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)

TheFox0x7 added 8 commits July 3, 2025 23:03
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
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jul 6, 2025
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin modifies/internal labels Jul 6, 2025
cmd/main.go Outdated
for i := range command.Commands {
prepareSubcommandWithGlobalFlags(command.Commands[i])
}
command.Before = prepareWorkPathAndCustomConf()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment resolved?

Image

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

@silverwind silverwind changed the title add genereted completions for shells add generated completions for shells Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin modifies/go Pull requests that update Go code modifies/internal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants