diff --git a/cfbs/cfbs_config.py b/cfbs/cfbs_config.py index aa7b00b..88e7187 100644 --- a/cfbs/cfbs_config.py +++ b/cfbs/cfbs_config.py @@ -131,30 +131,43 @@ def _add_using_url( remote_config = CFBSJson(path=config_path, url=url, url_commit=url_commit) provides = remote_config.get_provides() + add_all = True # URL specified in to_add, but no specific modules => let's add all (with a prompt) if len(to_add) == 0: modules = list(provides.values()) - print("Found %d modules in '%s':" % (len(modules), url)) - for m in modules: - print(" - " + m["name"]) if not any(modules): user_error("no modules available, nothing to do") - if not self.non_interactive: + print("Found %d modules in '%s':" % (len(modules), url)) + for m in modules: + deps = m.get("dependencies", []) + deps = "" if not deps else " (Depends on: " + ", ".join(deps) + ")" + print(" - " + m["name"] + deps) + if len(modules) > 1 and not self.non_interactive: answer = prompt_user( non_interactive=self.non_interactive, prompt="Do you want to add all %d of them?" % (len(modules)), choices=YES_NO_CHOICES, - default="no", + default="yes", ) if answer.lower() not in ("y", "yes"): - return + add_all = False else: missing = [k for k in to_add if k not in provides] if missing: user_error("Missing modules: " + ", ".join(missing)) modules = [provides[k] for k in to_add] - for module in modules: + for i, module in enumerate(modules, start=1): + if not add_all: + answer = prompt_user( + non_interactive=self.non_interactive, + prompt="(%d/%d) Do you want to add '%s'?" + % (i, len(modules), module["name"]), + choices=YES_NO_CHOICES, + default="yes", + ) + if answer.lower() not in ("y", "yes"): + continue self.add_with_dependencies(module, remote_config) @staticmethod diff --git a/cfbs/commands.py b/cfbs/commands.py index 66d4813..c05ab09 100644 --- a/cfbs/commands.py +++ b/cfbs/commands.py @@ -240,7 +240,7 @@ def init_command(index=None, masterfiles=None, non_interactive=False) -> int: CFBSConfig.reload() branch = None - to_add = "" + to_add = [] if masterfiles is None: if prompt_user( non_interactive, @@ -248,16 +248,18 @@ def init_command(index=None, masterfiles=None, non_interactive=False) -> int: choices=YES_NO_CHOICES, default="yes", ) in ("yes", "y"): - to_add = "masterfiles" + to_add = ["masterfiles"] else: - to_add = prompt_user( - non_interactive, - "Specify policy set to use instead (empty to skip)", - default="", - ) + to_add = [ + prompt_user( + non_interactive, + "Specify policy set to use instead (empty to skip)", + default="", + ) + ] elif re.match(r"[0-9]+(\.[0-9]+){2}(\-[0-9]+)?", masterfiles): log.debug("--masterfiles=%s appears to be a version number" % masterfiles) - to_add = "masterfiles@%s" % masterfiles + to_add = ["masterfiles@%s" % masterfiles] elif masterfiles != "no": """This appears to be a branch. Thus we'll add masterfiles normally and try to do the necessary modifications needed afterwards. I.e. @@ -266,7 +268,7 @@ def init_command(index=None, masterfiles=None, non_interactive=False) -> int: log.debug("--masterfiles=%s appears to be a branch" % masterfiles) branch = masterfiles - to_add = "masterfiles" + to_add = ["masterfiles"] if branch is not None: remote = "https://github.com/cfengine/masterfiles" @@ -276,9 +278,9 @@ def init_command(index=None, masterfiles=None, non_interactive=False) -> int: "Failed to find branch or tag %s at remote %s" % (branch, remote) ) log.debug("Current commit for masterfiles branch %s is %s" % (branch, commit)) - to_add = "%s@%s" % (remote, commit) + to_add = ["%s@%s" % (remote, commit), "masterfiles"] if to_add: - ret = add_command([to_add]) + ret = add_command(to_add, added_by="cfbs init") if ret != 0: return ret