Skip to content

Commit

Permalink
[rtwcli] ws create: raise RuntimeError on existing container (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
muritane authored Oct 31, 2024
1 parent 504c9cd commit 2da48fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 10 additions & 0 deletions rtwcli/rtw_cmds/rtw_cmds/workspace/create_verb.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from rtwcli.docker_utils import (
change_docker_path_permissions,
docker_build,
docker_container_exists,
docker_cp,
docker_exec_bash_cmd,
docker_stop,
Expand Down Expand Up @@ -899,6 +900,15 @@ def main(self, *, args):
rich.print(create_args)
logger.info("### CREATE ARGS ###")

if create_args.docker and docker_container_exists(create_args.container_name):
raise RuntimeError(
f"Docker container with name '{create_args.container_name}' already exists.\n"
"Options:\n"
" - renaming the workspace folder\n"
" - renaming the container name\n"
" - removing the existing container\n"
)

if create_args.docker:
self.build_intermediate_docker_image(create_args)

Expand Down
8 changes: 6 additions & 2 deletions rtwcli/rtwcli/rtwcli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import argparse
import signal
from rich.console import Console

from rtwcli.command import add_subparsers_on_demand

Expand Down Expand Up @@ -66,11 +67,14 @@ def main(*, script_name="rtw", argv=None, description=None, extension=None):
parser.print_help()
return 0

console = Console()

# call the main method of the extension
try:
rc = extension.main(parser=parser, args=args)
except KeyboardInterrupt:
rc = signal.SIGINT
except RuntimeError as e:
rc = str(e)
except RuntimeError:
console.print_exception()
return 1
return rc

0 comments on commit 2da48fd

Please sign in to comment.