Skip to content

Commit

Permalink
extract warning function and use BUILDS_DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianPommerening committed Jul 22, 2024
1 parent ce573c3 commit 4fb166a
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions driver/tab_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import subprocess
import sys

from . import returncodes
from . import util

try:
Expand All @@ -13,22 +14,27 @@
HAS_ARGCOMPLETE = False


def abort_tab_completion(warning):
argcomplete.warn(warning)
exit(returncodes.DRIVER_INPUT_ERROR)


def complete_build_arg(prefix, parsed_args, **kwargs):
if parsed_args.debug:
argcomplete.warn("The option --debug is an alias for --build=debug. Do no specify both --debug and --build.")
exit(1)
abort_tab_completion(
"The option --debug is an alias for --build=debug. Do no specify "
"both --debug and --build.")

builds_folder = Path(util.REPO_ROOT_DIR) / "builds"
if not builds_folder.exists():
argcomplete.warn("No build exists.")
exit(1)
return [p.name for p in builds_folder.iterdir() if p.is_dir()]
if not Path(util.BUILDS_DIR).exists():
abort_tab_completion("No build exists.")
return [p.name for p in Path(util.BUILDS_DIR).iterdir() if p.is_dir()]


def complete_planner_args(prefix, parsed_args, **kwargs):
if parsed_args.build and parsed_args.debug:
argcomplete.warn("The option --debug is an alias for --build=debug. Do no specify both --debug and --build.")
exit(1)
abort_tab_completion(
"The option --debug is an alias for --build=debug. Do no specify "
"both --debug and --build.")

build = parsed_args.build
if not build:
Expand Down Expand Up @@ -56,7 +62,7 @@ def complete_planner_args(prefix, parsed_args, **kwargs):
completions.append("--")

if parsed_args.filenames or double_dash_in_options:
bin_dir = Path(util.REPO_ROOT_DIR) / "builds" / build / "bin"
bin_dir = Path(util.BUILDS_DIR) / build / "bin"
if current_mode == "search":
if not last_option_was_mode_switch:
completions.append("--translate-options")
Expand Down

0 comments on commit 4fb166a

Please sign in to comment.