Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/dstack/_internal/cli/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from rich_argparse import RichHelpFormatter

from dstack._internal.cli.services.completion import ProjectNameCompleter
from dstack._internal.cli.utils.common import configure_logging
from dstack._internal.core.errors import CLIError
from dstack.api import Client

Expand Down Expand Up @@ -52,9 +53,16 @@ def _register(self):

@abstractmethod
def _command(self, args: argparse.Namespace):
self._configure_logging()
if not self.ACCEPT_EXTRA_ARGS and args.extra_args:
raise CLIError(f"Unrecognized arguments: {shlex.join(args.extra_args)}")

def _configure_logging(self) -> None:
"""
Override this method to configure command-specific logging
"""
configure_logging()


class APIBaseCommand(BaseCommand):
api: Client
Expand Down
5 changes: 5 additions & 0 deletions src/dstack/_internal/cli/commands/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,8 @@ def _command(self, args: argparse.Namespace):
log_level=uvicorn_log_level,
workers=1,
)

def _configure_logging(self) -> None:
# Server logging is configured in the FastAPI lifespan function.
# No need to configure CLI logging.
pass
4 changes: 1 addition & 3 deletions src/dstack/_internal/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from dstack._internal.cli.commands.stats import StatsCommand
from dstack._internal.cli.commands.stop import StopCommand
from dstack._internal.cli.commands.volume import VolumeCommand
from dstack._internal.cli.utils.common import _colors, configure_logging, console
from dstack._internal.cli.utils.common import _colors, console
from dstack._internal.cli.utils.updates import check_for_updates
from dstack._internal.core.errors import ClientError, CLIError, ConfigurationError, SSHError
from dstack._internal.core.services.ssh.client import get_ssh_client_info
Expand All @@ -39,8 +39,6 @@ def main():
RichHelpFormatter.styles["argparse.groups"] = "bold grey74"
RichHelpFormatter.styles["argparse.text"] = "grey74"

configure_logging()

parser = argparse.ArgumentParser(
description=(
"Not sure where to start?"
Expand Down