Skip to content

Commit

Permalink
CTX-6123: saving changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdan Tintor committed Aug 29, 2024
1 parent 8b07079 commit fb6115e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
37 changes: 37 additions & 0 deletions coretex/cli/commands/base_command.py
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

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
12 changes: 5 additions & 7 deletions coretex/cli/commands/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down Expand Up @@ -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():
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion coretex/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from typing import Optional
from importlib.metadata import version as getLibraryVersion

import click
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion coretex/cli/modules/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit fb6115e

Please sign in to comment.