diff --git a/src/dcr/cli/__init__.py b/src/dcr/cli/__init__.py index f450ff1..de59894 100644 --- a/src/dcr/cli/__init__.py +++ b/src/dcr/cli/__init__.py @@ -4,6 +4,7 @@ from .new import new from .run import run from .build import build from .clean import clean +from .update import update __all__ = [ @@ -13,4 +14,5 @@ __all__ = [ "run", "build", "clean", + "update", ] diff --git a/src/dcr/cli/help.py b/src/dcr/cli/help.py index 8d2231f..693fdd1 100644 --- a/src/dcr/cli/help.py +++ b/src/dcr/cli/help.py @@ -14,7 +14,9 @@ def help() -> int: " build [--profile] Собрать проект (по умолчанию: --debug)", " run [--profile] Собрать и запустить (по умолчанию: --debug)", " clean Удалить директорию target", - " help Показать эту справку", + "ФЛАГИ:", + " --help Показать справку по команде", + " --update Обновить dcr до актуальной версии", "", "ОПЦИИ:", " --debug Сборка с профилем debug", diff --git a/src/dcr/cli/update.py b/src/dcr/cli/update.py new file mode 100644 index 0000000..f6e7803 --- /dev/null +++ b/src/dcr/cli/update.py @@ -0,0 +1,23 @@ +import platform +import shutil +import subprocess + + +def update(args: list[str] | None = None) -> int: + if args and len(args) > 0: + print("Ошибка: команда не поддежривает аргументы") + return 1 + if platform.system() != "Linux": + print("Ошибка: обновление поддерживается только на Linux") + return 1 + if shutil.which("curl") is None: + print("Ошибка: не найден curl") + return 1 + try: + subprocess.run( + ["bash", "-c", "curl -fsSL dcr.zov.tatar | bash"], check=True + ) + return 0 + except subprocess.CalledProcessError: + print("Ошибка: не удалось выполнить обновление") + return 1 diff --git a/src/dcr/main.py b/src/dcr/main.py index 9e308c0..93d4dad 100644 --- a/src/dcr/main.py +++ b/src/dcr/main.py @@ -3,7 +3,7 @@ import sys def main() -> int: - if len(sys.argv) < 2 or sys.argv[1] == "--help": + if len(sys.argv) < 2: cli.help() return 0 @@ -21,8 +21,12 @@ def main() -> int: cli.run(args) case "clean": cli.clean(args) + case "--help": + cli.help() + case "--update": + cli.update(args) case _: - print("Unknown command") + print("Неизвестная команда или аргумент") return 0