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

Add argcompleter (update deps as well) #46

Merged
merged 2 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions andeboxlib/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# PYTHON_ARGCOMPLETE_OK
# (c) 2021-2022, Alexei Znamensky <russoz@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

Expand All @@ -18,6 +19,8 @@
from .exceptions import AndeboxException
from .util import set_dir

import argcomplete


#
# Adapted from:
Expand Down Expand Up @@ -67,7 +70,9 @@ def _make_parser() -> argparse.ArgumentParser:
help="path to the virtual environment where andebox and ansible are installed",
type=Path,
)
subparser = parser.add_subparsers(dest="action", required=True)
subparser = parser.add_subparsers(
dest="action", required=True, metavar=" ".join([a.name for a in actions])
)

for action in actions:
action.make_parser(subparser)
Expand All @@ -76,22 +81,25 @@ def _make_parser() -> argparse.ArgumentParser:


class AndeBox:
def __init__(self) -> None:
def __init__(self, args: argparse.Namespace) -> None:
self.actions = {ac.name: ac() for ac in actions}
self.parser = _make_parser()
self.args = args

def run(self):
args = self.parser.parse_args()
context = create_context(args)
context = create_context(self.args)
with set_dir(context.base_dir):
action = self.actions[args.action]
action = self.actions[self.args.action]
action.run(context)


def run():
parser = _make_parser()
argcomplete.autocomplete(parser)
args = parser.parse_args()

try:
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
box = AndeBox()
box = AndeBox(args)
box.run()
return 0
except KeyboardInterrupt:
Expand Down
Loading
Loading