Skip to content

Commit

Permalink
save default container name in variable
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbusch committed Jun 12, 2023
1 parent f95ed19 commit 9300a79
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions docker-run-cli/src/docker_run/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
if isinstance(cls, type) and issubclass(cls, Plugin) and cls is not Plugin:
PLUGINS.append(cls)

DEFAULT_CONTAINER_NAME = validDockerContainerName(os.path.basename(os.getcwd()))

def parseArguments() -> Tuple[argparse.Namespace, List[str], List[str]]:

Expand All @@ -45,7 +46,7 @@ def format_help(self):

parser.add_argument("--help", action="help", default=argparse.SUPPRESS, help="show this help message and exit")
parser.add_argument("--image", help="image name (may also be specified without --image as last argument before command)")
parser.add_argument("--name", default=validDockerContainerName(os.path.basename(os.getcwd())), help="container name; generates `docker exec` command if already running")
parser.add_argument("--name", default=DEFAULT_CONTAINER_NAME, help="container name; generates `docker exec` command if already running")
parser.add_argument("--no-name", action="store_true", help="disable automatic container name (current directory)")
parser.add_argument("--verbose", action="store_true", help="print generated command")
parser.add_argument("--version", action="store_true", help="show program's version number and exit")
Expand Down Expand Up @@ -94,7 +95,7 @@ def buildDockerCommand(args: Dict[str, Any], unknown_args: List[str] = [], cmd_a
running_containers = runCommand('docker ps --format "{{.Names}}"')[0].split('\n')
new_container = not (args["name"] in running_containers)
if not new_container and args["image"] is not None and len(args["image"]) > 0:
args["name"] = None if args["name"] == validDockerContainerName(os.path.basename(os.getcwd())) else args["name"]
args["name"] = None if args["name"] == DEFAULT_CONTAINER_NAME else args["name"]
new_container = True

if new_container: # docker run
Expand Down

0 comments on commit 9300a79

Please sign in to comment.