mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 16:54:59 +00:00
feat: add shell completion generation using shtab
This commit is contained in:
parent
c3d4fdb4c1
commit
a2ecc5883b
1 changed files with 28 additions and 8 deletions
|
@ -6,6 +6,7 @@ import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import configargparse
|
import configargparse
|
||||||
|
import shtab
|
||||||
|
|
||||||
from aider import __version__
|
from aider import __version__
|
||||||
from aider.args_formatter import (
|
from aider.args_formatter import (
|
||||||
|
@ -858,16 +859,35 @@ def get_sample_dotenv():
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
arg = sys.argv[1] if len(sys.argv[1:]) else None
|
if len(sys.argv) > 1:
|
||||||
|
command = sys.argv[1]
|
||||||
if arg == "md":
|
|
||||||
print(get_md_help())
|
|
||||||
elif arg == "dotenv":
|
|
||||||
print(get_sample_dotenv())
|
|
||||||
else:
|
else:
|
||||||
|
command = "yaml" # Default to yaml if no command is given
|
||||||
|
|
||||||
|
if command == "md":
|
||||||
|
print(get_md_help())
|
||||||
|
elif command == "dotenv":
|
||||||
|
print(get_sample_dotenv())
|
||||||
|
elif command == "yaml":
|
||||||
|
print(get_sample_yaml())
|
||||||
|
elif command == "completion":
|
||||||
|
if len(sys.argv) > 2:
|
||||||
|
shell = sys.argv[2]
|
||||||
|
if shell not in shtab.SUPPORTED_SHELLS:
|
||||||
|
print(f"Error: Unsupported shell '{shell}'.", file=sys.stderr)
|
||||||
|
print(f"Supported shells are: {', '.join(shtab.SUPPORTED_SHELLS)}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
parser = get_parser([], None)
|
||||||
|
print(shtab.complete(parser, shell=shell, prog="aider"))
|
||||||
|
else:
|
||||||
|
print("Error: Please specify a shell for completion.", file=sys.stderr)
|
||||||
|
print(f"Usage: python {sys.argv[0]} completion <shell_name>", file=sys.stderr)
|
||||||
|
print(f"Supported shells are: {', '.join(shtab.SUPPORTED_SHELLS)}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
# Default to YAML for any other unrecognized argument, or if 'yaml' was explicitly passed
|
||||||
print(get_sample_yaml())
|
print(get_sample_yaml())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
status = main()
|
main()
|
||||||
sys.exit(status)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue