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

Fix tab-completion to work with helper mode #851

Merged
merged 1 commit into from
May 31, 2023
Merged

Conversation

olsen232
Copy link
Collaborator

Click tab completion uses the name of the program for various environment variables eg _KART_COMPLETE.
Our program name varies depending on how the program is run kart vs kart_cli depending on helper mode etc.
Since we can't be sure if the way kart is currently being run is the same as it was run when tab-completion was installed, its safest to stick to one "canoncial" program name for tab-completion at all times. Click lets us do this. The chosen name is "kart" and therefore the variable is _KART_COMPLETE.

Checklist:

  • Have you reviewed your own change?
  • Have you included test(s)?
  • Have you updated the changelog?

Click tab completion uses the name of the program for various
environment variables eg _KART_COMPLETE.
Our program name varies depending on how the program is run
kart vs kart_cli depending on helper mode etc.
Since we can't be sure if the way kart is currently being run is the
same as it was run when tab-completion was installed, its safest to
stick to one "canoncial" program name for tab-completion at all times.
Click lets us do this. The chosen name is "kart" and therefore the
variable is _KART_COMPLETE.
@olsen232 olsen232 requested a review from craigds May 31, 2023 02:11
@@ -403,7 +403,9 @@ def load_commands_from_args(args, skip_first_arg=True):
def entrypoint():
freeze_support()
load_commands_from_args(sys.argv)
cli()
# Don't let helper mode mess up the usage-text, or the shell complete environment variables.
prog_name = "kart" if os.path.basename(sys.argv[0]) == "kart_cli" else None
Copy link
Member

Choose a reason for hiding this comment

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

what's the None case here for? Would that handle a case where you created a shell alias/symlink to kart called k or something like that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it seems to correctly handle that case - if you rename or alias kart, you get usage info for the renamed kart.
Depending on why kart was renamed or aliased, this may or may not be desirable, but at least it's not like tab-completion where something breaks if we get it wrong.

@olsen232 olsen232 merged commit 1ba28df into master May 31, 2023
@olsen232 olsen232 deleted the fix-tab-completion branch May 31, 2023 02:58
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 this pull request may close these issues.

2 participants