diff --git a/src/commands/remote/__init__.py b/src/commands/remote/__init__.py new file mode 100644 index 0000000..70ff124 --- /dev/null +++ b/src/commands/remote/__init__.py @@ -0,0 +1,3 @@ +from .remote_module import RemoteModule + +__all__ = ["RemoteModule"] diff --git a/src/commands/remote/remote_cli.py b/src/commands/remote/remote_cli.py new file mode 100644 index 0000000..4c4d6e5 --- /dev/null +++ b/src/commands/remote/remote_cli.py @@ -0,0 +1,61 @@ +from fabric import Connection +from injector import inject + +from common import Command, CommandGroup, CommandOption, CommandArgument, StdoutSeverity + + +class RemoteCommand(Command): + name = "run" + + short_help = "Run a command on a remote host." + + help = """ + remote host trying to het it done + """ + + params = [ + CommandArgument(["command"], type=str, nargs=-1), + CommandOption(["--host", "-H"], type=str, help="qwer", required=True), + CommandOption(["--user", "-U"], type=str, help="qwer", required=False), + CommandOption(["--port", "-P"], type=str, help="qwer", required=False), + ] + + def __init__(self) -> None: + super().__init__() + + def run(self, command, **kwargs): + breakpoint() + print("Running remote command...") + try: + result = Connection(**kwargs).run(" ".join(command)) + except Exception as e: + print(e) + + +class RemoteCli(CommandGroup): + name = "remote" + + short_help = "Run a command on a remote host." + + help = """ +'das-cli remote-command' allows you to run any das-cli command on a remote host. +.SH EXAMPLES: + +Update the remote host DAS CLI to the latest version available via APT repository. + +$ das-cli remote-command -H -- update-version +""" + + params = [] + + @inject + def __init__( + self, + remote: RemoteCommand, + ) -> None: + super().__init__() + self.add_commands( + [ + remote.command, + ] + ) diff --git a/src/commands/remote/remote_module.py b/src/commands/remote/remote_module.py new file mode 100644 index 0000000..a5b7880 --- /dev/null +++ b/src/commands/remote/remote_module.py @@ -0,0 +1,8 @@ +from common import Module + +from .remote_cli import RemoteCli + + +class RemoteModule(Module): + _instance = RemoteCli + _dependency_injection = [] diff --git a/src/das_cli.py b/src/das_cli.py index 39b6c5b..af718f9 100644 --- a/src/das_cli.py +++ b/src/das_cli.py @@ -10,6 +10,7 @@ from commands.metta import MettaModule from commands.python_library import PythonLibraryModule from commands.release_notes import ReleaseNotesModule +from commands.remote import RemoteModule MODULES = [ ConfigModule, @@ -21,6 +22,7 @@ MettaModule, PythonLibraryModule, ReleaseNotesModule, + RemoteModule, ]