From fb6115e2775df34a457451d36bca6a08cbc51d2e Mon Sep 17 00:00:00 2001 From: Bogdan Tintor Date: Thu, 29 Aug 2024 11:31:01 +0200 Subject: [PATCH] CTX-6123: saving changes --- coretex/cli/commands/base_command.py | 37 ++++++++++++++++++++++++++++ coretex/cli/commands/node.py | 12 ++++----- coretex/cli/main.py | 4 ++- coretex/cli/modules/node.py | 2 +- 4 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 coretex/cli/commands/base_command.py diff --git a/coretex/cli/commands/base_command.py b/coretex/cli/commands/base_command.py new file mode 100644 index 00000000..a1e7eda8 --- /dev/null +++ b/coretex/cli/commands/base_command.py @@ -0,0 +1,37 @@ +# Copyright (C) 2023 Coretex LLC + +# This file is part of Coretex.ai + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from typing import Optional, Any, Callable + +import click + + +def base_command(name: Optional[str] = None, cls: Any = None, **attrs: Any) -> Any: + def decorator(f: Callable[..., Any]) -> Any: + f = click.option('--verbose', is_flag = True, help = "Enables berbose mode")(f) + + # Wrapper function to handle the verbose argument internally + def wrapper(*args, **kwargs): + verbose = kwargs.pop('verbose', False) + if verbose: + click.echo("Verbose mode is enabled.") + else: + click.echo("Verbose mode is disabled.") + return f(*args, **kwargs) + + return click.command(name = name, cls = cls, **attrs)(f) + return decorator diff --git a/coretex/cli/commands/node.py b/coretex/cli/commands/node.py index 0e28622e..2b06f498 100644 --- a/coretex/cli/commands/node.py +++ b/coretex/cli/commands/node.py @@ -19,6 +19,7 @@ import click +from .base_command import base_command from ..modules import ui from ..modules import node as node_module from ..modules.node import NodeStatus @@ -29,11 +30,10 @@ from ...configuration import NodeConfiguration, InvalidConfiguration, ConfigurationNotFound -@click.command() +@base_command() @click.option("--image", type = str, help = "Docker image url") -@click.option("--verbose", "verbose", is_flag = True, help = "Shows detailed output of command execution.") @onBeforeCommandExecute(node_module.initializeNodeConfiguration) -def start(image: Optional[str], verbose: bool = False) -> None: +def start(image: Optional[str]) -> None: nodeConfig = NodeConfiguration.load() if node_module.isRunning(): @@ -66,8 +66,7 @@ def start(image: Optional[str], verbose: bool = False) -> None: @click.command() -@click.option("--verbose", "verbose", is_flag = True, help = "Shows detailed output of command execution.") -def stop(verbose: bool = False) -> None: +def stop() -> None: nodeConfig = NodeConfiguration.load() if not node_module.isRunning(): @@ -80,9 +79,8 @@ def stop(verbose: bool = False) -> None: @click.command() @click.option("-y", "autoAccept", is_flag = True, help = "Accepts all prompts.") @click.option("-n", "autoDecline", is_flag = True, help = "Declines all prompts.") -@click.option("--verbose", "verbose", is_flag = True, help = "Shows detailed output of command execution.") @onBeforeCommandExecute(node_module.initializeNodeConfiguration) -def update(autoAccept: bool, autoDecline: bool, verbose: bool = False) -> None: +def update(autoAccept: bool, autoDecline: bool) -> None: if autoAccept and autoDecline: ui.errorEcho("Only one of the flags (\"-y\" or \"-n\") can be used at the same time.") return diff --git a/coretex/cli/main.py b/coretex/cli/main.py index 96da0e0b..5453f98b 100644 --- a/coretex/cli/main.py +++ b/coretex/cli/main.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from typing import Optional from importlib.metadata import version as getLibraryVersion import click @@ -58,7 +59,8 @@ def update() -> None: ui.stdEcho("Coretex version is up to date.") -@click.group(cls = ClickExceptionInterceptor) +# @click.group(cls = ClickExceptionInterceptor) +@click.group() @utils.onBeforeCommandExecute(utils.checkLibVersion, excludeSubcommands = ["update"]) def cli() -> None: pass diff --git a/coretex/cli/modules/node.py b/coretex/cli/modules/node.py index 5100da98..051bc2a6 100644 --- a/coretex/cli/modules/node.py +++ b/coretex/cli/modules/node.py @@ -445,7 +445,7 @@ def configureNode(advanced: bool) -> NodeConfiguration: nodeConfig.endpointInvocationPrice = promptInvocationPrice() else: - ui.stdEcho("To configure node manually run coretex node config with --verbose flag.") + ui.stdEcho("To configure node manually run coretex node config with --advanced flag.") publicKey: Optional[bytes] = None if isinstance(nodeConfig.secret, str) and nodeConfig.secret != config_defaults.DEFAULT_NODE_SECRET: