-
Couldn't load subscription status.
- Fork 1.3k
completion: autogenerate #3921
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
Merged
Merged
completion: autogenerate #3921
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
6de665f
cli: split main_parser
casperdcl e35a363
cli: basic parser tree printing
casperdcl ebb8f21
cli: major completion tidy
casperdcl 743a6dc
completion: more missing root commands
casperdcl d21f48d
completion: much automagic such beauty
casperdcl e0ee359
tests: bash completion
casperdcl 62d8f48
tests: completion: tidy script a little
casperdcl 387896d
minor tidy
casperdcl 7769b6c
command: positional name consistency
casperdcl 732f118
completion: bash: add logging
casperdcl 82ca4b2
double-check renames and consistency
casperdcl 3673e5f
cli: add completion subcommand
casperdcl d900333
ci: completion: update test
casperdcl 5f41c32
minor logging
casperdcl 3f2ea55
more completion logging verbosity
casperdcl a7bdb8c
fix completion of files
casperdcl ae49399
add shtab
casperdcl dd82a7f
purge unneeded completion => shtab
casperdcl edfd3c2
completion: neaten UI
casperdcl 11a3647
completion: use `shtab>=0.0.2`
casperdcl 2f23ccc
completion: purge hardcoded completions!
casperdcl ef3ce8f
Merge remote-tracking branch 'upstream/master' into completion-auto
casperdcl c13dd09
revert unneeded renames for now
casperdcl dfcf3f2
fix isort
casperdcl 3600385
completion: tidy CLI API
casperdcl 79e8e87
fix snap build
casperdcl f39cbc8
fix snap build again
casperdcl 8b27135
snap: internally build completion
casperdcl 2267ad9
allow repo-less completion
casperdcl 1386ffa
command: tidy headless logic
casperdcl ac00de1
use CmdBaseNoRepo
casperdcl 5b80e08
better DVC-file completion
casperdcl e211340
merge command.choices -> command.completion
casperdcl 9c204f3
drop choices class
casperdcl 80157c2
remove completion optionals
casperdcl 18a0e58
tidy docs
casperdcl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import argparse | ||
| import logging | ||
|
|
||
| import shtab | ||
|
|
||
| from dvc.command.base import CmdBaseNoRepo, append_doc_link | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
| CHOICE_FUNCTIONS = { | ||
| "bash": {"DVCFile": "_dvc_compgen_DVCFiles"}, | ||
| "zsh": {"DVCFile": "_files -g '(*?.dvc|Dvcfile|dvc.yaml)'"}, | ||
| } | ||
| PREAMBLE = { | ||
| "bash": """ | ||
| # $1=COMP_WORDS[1] | ||
| _dvc_compgen_DVCFiles() { | ||
| compgen -d -S '/' -- $1 # recurse into subdirs | ||
| compgen -f -X '!*?.dvc' -- $1 | ||
| compgen -f -X '!*Dvcfile' -- $1 | ||
| compgen -f -X '!*dvc.yaml' -- $1 | ||
| } | ||
| """, | ||
| "zsh": "", | ||
| } | ||
|
|
||
|
|
||
| class Optional(shtab.Optional): | ||
| DVC_FILE = [shtab.Choice("DVCFile", required=False)] | ||
|
|
||
|
|
||
| class Required(shtab.Required): | ||
| DVC_FILE = [shtab.Choice("DVCFile", required=True)] | ||
|
|
||
|
|
||
| class CmdCompletion(CmdBaseNoRepo): | ||
| def run(self): | ||
| from dvc.cli import get_main_parser | ||
|
|
||
| parser = get_main_parser() | ||
| shell = self.args.shell | ||
| script = shtab.complete( | ||
| parser, | ||
| shell=shell, | ||
| preamble=PREAMBLE[shell], | ||
| choice_functions=CHOICE_FUNCTIONS[shell], | ||
| ) | ||
| print(script) | ||
| return 0 | ||
|
|
||
|
|
||
| def add_parser(subparsers, parent_parser): | ||
| COMPLETION_HELP = "Generate shell tab completion." | ||
| COMPLETION_DESCRIPTION = "Prints out shell tab completion scripts." | ||
| completion_parser = subparsers.add_parser( | ||
| "completion", | ||
| parents=[parent_parser], | ||
| description=append_doc_link(COMPLETION_DESCRIPTION, "completion"), | ||
| help=COMPLETION_HELP, | ||
| formatter_class=argparse.RawDescriptionHelpFormatter, | ||
| ) | ||
| completion_parser.add_argument( | ||
| "-s", | ||
| "--shell", | ||
| help="Shell syntax for completions.", | ||
| default="bash", | ||
| choices=["bash", "zsh"], | ||
| ) | ||
| completion_parser.set_defaults(func=CmdCompletion) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.