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

Allow to customize the name of the command for completion #355

Closed
martinbonnin opened this issue Jun 3, 2022 · 3 comments · Fixed by #356
Closed

Allow to customize the name of the command for completion #355

martinbonnin opened this issue Jun 3, 2022 · 3 comments · Fixed by #356

Comments

@martinbonnin
Copy link

martinbonnin commented Jun 3, 2022

The name of the main command in the code isn't always the same one as the name of the shell command being actually run. Typically, my main command is often named "main" and I then create scripts that launch the jar.

It would be nice to be able to customize that name for the purpose of completion

launcher_script.main.kts generate-completion --shell zsh --name launcher_script.main.kts

Edit: somewhat an overshoot of that issue but looks like CompletionCommand will always print the completion for itself?

@ajalt
Copy link
Owner

ajalt commented Jun 5, 2022

Thanks for the bug report!

#356 fixes the command not generating completion for its parent.

The completion output uses the command name. I could add an option to customize that, but the help and usage output also use the command name, so they would seemingly be incorrect. Does setting the root command name to match the script not work for you? e.g. class Main : CliktCommand(name="launcher_script.main.kts")

@martinbonnin
Copy link
Author

Does setting the root command name to match the script not work for you?

My use case is kind of an edge case I guess.

The jar is distributed on mavenCentral as foo-cli.jar and the default command name should be foo-cli I guess. Except I did not make it a shadow jar or distribute a dist zip, instead I'm using Kotlin scripts to resolve the dependencies. I found that it's a pretty convenient way to download dependencies (and potentially share them across different clis):

#!/usr/bin/env kotlin

// To regenerate autocompletion, use:
// foo_cli.main.kts generate-completion --shell zsh --name foo_cli.main.kts > ~/.foo_cli_completion

@file:DependsOn("com.example:foo_cli:$latest")

import com.example.main

main(args)

With that, it'd feel weird making the jar know about .main.kts but maybe I just need to distribute that correctly.

@ajalt
Copy link
Owner

ajalt commented Jun 5, 2022

You could always add an optional script name parameter to your main in order to set the command name if you don't want it to know about the script. If you don't, the help output will be something like

Usage: foo-cli [OPTIONS] ARG1 ARG2...

Which is misleading if the user needs to enter foo_cli.main.kts instead of foo-cli

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 a pull request may close this issue.

2 participants