Rewrote using command factory
This commit is contained in:
parent
84571f1692
commit
537a0d8015
12 changed files with 287 additions and 196 deletions
dockge_cli/commands
0
dockge_cli/commands/__init__.py
Normal file
0
dockge_cli/commands/__init__.py
Normal file
74
dockge_cli/commands/descriptors.json
Normal file
74
dockge_cli/commands/descriptors.json
Normal file
|
@ -0,0 +1,74 @@
|
|||
[
|
||||
{
|
||||
"command": "host",
|
||||
"description": "Sets and gets the URI of the dockge instance. Remove any unnecessary subdomains/protocols from the URI",
|
||||
"args": 1,
|
||||
"optional": true
|
||||
},
|
||||
{
|
||||
"command": "login",
|
||||
"description": "Logs into a given dockge account, either with an interactive dialogue or by passing --user and --password",
|
||||
"args": 2,
|
||||
"optional": true
|
||||
},
|
||||
{
|
||||
"command": "logout",
|
||||
"description": "Removes the credentials from the local storage.",
|
||||
"args": 0,
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
"command": "list",
|
||||
"description": "Lists all available stacks with their status",
|
||||
"args": 0,
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
"command": "status",
|
||||
"description": "Returns the status of one stack",
|
||||
"args": 1,
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
"command": "restart",
|
||||
"description": "Restarts a given stack",
|
||||
"args": 1,
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
"command": "start",
|
||||
"description": "Starts a given stack",
|
||||
"args": 1,
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
"command": "stop",
|
||||
"description": "Stops a given stack",
|
||||
"args": 1,
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
"command": "down",
|
||||
"description": "Stop & Downs a given stack",
|
||||
"args": 1,
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
"command": "update",
|
||||
"description": "Updates a stack",
|
||||
"args": 1,
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
"command": "exit",
|
||||
"description": "Exits the CLI - this will reset all settings, including credentials and host",
|
||||
"args": 0,
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
"command": "help",
|
||||
"description": "Displays helping hints for commands",
|
||||
"args": 1,
|
||||
"optional": true
|
||||
}
|
||||
]
|
30
dockge_cli/commands/factory.py
Normal file
30
dockge_cli/commands/factory.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
import pathlib
|
||||
import json
|
||||
from typing import List, Callable
|
||||
from pydantic import BaseModel
|
||||
|
||||
from ..components.bindings import binds
|
||||
|
||||
class Descriptor(BaseModel):
|
||||
command: str
|
||||
description: str
|
||||
args: int
|
||||
optional: bool
|
||||
|
||||
class Command(Descriptor):
|
||||
binding: Callable
|
||||
|
||||
_descriptor_file = pathlib.Path(__file__).parent / "descriptors.json"
|
||||
|
||||
commands: dict[str, Command] = {}
|
||||
|
||||
with open(_descriptor_file, "r", encoding="utf-8") as file:
|
||||
descriptors: List[Descriptor] = json.load(file)
|
||||
for descriptor in descriptors:
|
||||
commands.update({
|
||||
descriptor["command"]:
|
||||
Command(
|
||||
**descriptor,
|
||||
binding=binds[descriptor["command"]]
|
||||
)
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue