mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
add moulinette display/prompt mocking
This commit is contained in:
parent
ec499b3438
commit
4680c69b9f
2 changed files with 23 additions and 2 deletions
|
@ -1,6 +1,9 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from yunohost.interface.base import InterfaceKind
|
||||||
|
|
||||||
if os.environ.get("INTERFACE", "cli") == "cli":
|
if os.environ.get("INTERFACE", "cli") == "cli":
|
||||||
from yunohost.interface.cli import Interface # noqa
|
from yunohost.interface.cli import Interface
|
||||||
else:
|
else:
|
||||||
from yunohost.interface.api import Interface # noqa
|
from yunohost.interface.api import Interface
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ from __future__ import (
|
||||||
annotations,
|
annotations,
|
||||||
) # Enable self reference a class in its own method arguments
|
) # Enable self reference a class in its own method arguments
|
||||||
|
|
||||||
|
import os
|
||||||
import inspect
|
import inspect
|
||||||
import typer
|
import typer
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -44,6 +45,23 @@ class Interface(BaseInterface):
|
||||||
interface.instance, name=interface.name, help=interface.help
|
interface.instance, name=interface.name, help=interface.help
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def display(content: str):
|
||||||
|
if os.environ.get("INTERFACE") == "cli":
|
||||||
|
rprint(content)
|
||||||
|
else:
|
||||||
|
from moulinette import Moulinette
|
||||||
|
Moulinette.display(content)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def prompt(ask: str, is_password=False, confirm=False, **kwargs):
|
||||||
|
if os.environ.get("INTERFACE") == "cli":
|
||||||
|
return typer.prompt(ask, hide_input=is_password, confirmation_prompt=confirm)
|
||||||
|
else:
|
||||||
|
from moulinette import Moulinette
|
||||||
|
return Moulinette.prompt(ask, is_password=is_password, confirm=confirm, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def cli(self, command_def: str, **extra_data):
|
def cli(self, command_def: str, **extra_data):
|
||||||
def decorator(func: Callable):
|
def decorator(func: Callable):
|
||||||
signature = inspect.signature(func)
|
signature = inspect.signature(func)
|
||||||
|
|
Loading…
Add table
Reference in a new issue