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

[Bug] bash autocompletion has strange behavior under certain conditions #116

Open
alkatar21 opened this issue Oct 31, 2022 · 1 comment
Open
Labels
external-request You asked, we did help-wanted We need help shell-bash

Comments

@alkatar21
Copy link

dvc==2.31.0
shtab==1.5.6

I for example have dvc stage add --name Test -d folder/file -w and want to remove folder/file and replace it. Than -w is autocompleted (dvc stage add --name Test -d -w -w) instead of an option for folders.
So for some reason the autocompletion with tab adds a -w instead of autocompletion for files and folders in this case. But the autocompletion works if nothing follows after -d.
This gif shows the behavior:
Bug1

An reproducable example is the following provided by pared#9484 on the Discord server:

#!/usr/bin/env python3

import argparse
import shtab

parser = argparse.ArgumentParser()
shtab.add_argument_to(parser, ["--print-completion"])

subparsers = parser.add_subparsers()

subparser1 = subparsers.add_parser('bla', help="hi")
subparser1.add_argument(
            "-d",
            "--directory",
            action="store",
            required=True,
            dest="dir",
            help="this is directory",
        ).complete = shtab.DIRECTORY  # type: ignore
subparser1.add_argument(
        "-w",
        "--wdir",
        help="Directory within your repo to run your command in.",
        metavar="<path>",
    )
subparser2 = subparsers.add_parser('blub', help="hi")

args = parser.parse_args()

Further context: https://discord.com/channels/485586884165107732/485596304961962003/1036650841425313843

@casperdcl casperdcl added help-wanted We need help external-request You asked, we did labels Nov 2, 2022
@casperdcl casperdcl self-assigned this Nov 2, 2022
@casperdcl
Copy link
Collaborator

Ah so dvc stage add -d <TAB> works, but dvc stage add -d <TAB> -w (tabbing in the middle of the command) doesn't work.

Happy to accept a PR fixing this (if at all possible).

@casperdcl casperdcl removed their assignment Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external-request You asked, we did help-wanted We need help shell-bash
Projects
None yet
Development

No branches or pull requests

3 participants