From 71fe46e881d0e21083059c1895de79af80335a70 Mon Sep 17 00:00:00 2001 From: Adrian Malacoda Date: Thu, 20 Aug 2020 02:44:55 -0500 Subject: [PATCH] Add ability to run multiple "actions" (commit/rm) and even an otherworld command (potentially starting a new container) --- otherworld | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/otherworld b/otherworld index 4114ff7..2444c69 100755 --- a/otherworld +++ b/otherworld @@ -119,6 +119,8 @@ command_user = user user_volumes = USER_VOLUMES pull = False +actions = [] + command_env = {} quiet = False @@ -128,16 +130,11 @@ while len(command) > 0: command = command[1:] quiet = True elif arg == "--rm": - if not quiet: - print(f">> Removing container: {container_name}") - docker_rm(container_name) - sys.exit(0) + actions.append("rm") + command = command[1:] elif arg == "--commit": - image_name = get_generated_image_name(container_name) - if not quiet: - print(f">> Committing container: {container_name} to image: {image_name}") - docker_commit(container_name, image_name) - sys.exit(0) + actions.append("commit") + command = command[1:] elif arg == "--sudo": command_user = "root" command = command[1:] @@ -164,7 +161,22 @@ while len(command) > 0: else: break -if len(command) == 0: +if actions: + if "commit" in actions: + target_image_name = get_generated_image_name(container_name) + if not quiet: + print(f">> Committing container: {container_name} to image: {target_image_name}") + docker_commit(container_name, target_image_name) + + if "rm" in actions: + if not quiet: + print(f">> Removing container: {container_name}") + docker_rm(container_name) + + if not command: + sys.exit(0) + +if not command: command = DEFAULT_COMMAND container = None