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 RemoteCommand to das-cli #108

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions src/commands/remote/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .remote_module import RemoteModule

__all__ = ["RemoteModule"]
61 changes: 61 additions & 0 deletions src/commands/remote/remote_cli.py
Original file line number Diff line number Diff line change
@@ -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 <remote_host> -- update-version
"""

params = []

@inject
def __init__(
self,
remote: RemoteCommand,
) -> None:
super().__init__()
self.add_commands(
[
remote.command,
]
)
8 changes: 8 additions & 0 deletions src/commands/remote/remote_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from common import Module

from .remote_cli import RemoteCli


class RemoteModule(Module):
_instance = RemoteCli
_dependency_injection = []
2 changes: 2 additions & 0 deletions src/das_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,6 +22,7 @@
MettaModule,
PythonLibraryModule,
ReleaseNotesModule,
RemoteModule,
]


Expand Down
Loading