From 7e017a3de0012464fd508f4b2e192850a5b029ec Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 20 Sep 2019 19:30:12 -0400 Subject: [PATCH 1/3] --levels --- bake/cli.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/bake/cli.py b/bake/cli.py index 999b768..8c27aab 100644 --- a/bake/cli.py +++ b/bake/cli.py @@ -100,12 +100,18 @@ def echo_json(obj): ) @click.option( "--list", - "-l", "_list", default=False, is_flag=True, help="Lists available tasks (and their dependencies).", ) +@click.option( + "--levels", + "-l", + default=1, + nargs=1, + help="Lists available tasks (and their dependencies).", +) @click.option( "--help", "-h", default=False, is_flag=True, help="Show this message and exit." ) @@ -179,6 +185,7 @@ def entrypoint( bakefile, arguments, _list, + levels, _continue, environ_json, debug, @@ -283,7 +290,12 @@ def entrypoint( if _list: __list_json = {"tasks": {}} + task_list = [] for _task in bakefile.tasks: + if len(_task.split("/")) <= levels: + task_list.append(_task) + + for _task in task_list: depends_on = bakefile[_task].depends_on( include_filters=False, recursive=True ) @@ -308,6 +320,17 @@ def entrypoint( err=False, ) + if not silent: + tasks_unechoed = len(bakefile.tasks) - len(task_list) + bake_command = str(click.style(f"bake -l {levels + 1}", fg="red")) + if tasks_unechoed: + # click.echo(err=True) + click.echo( + f"Note: {tasks_unechoed} more tasks are available. " + f"Please use $ {bake_command} to see more.", + err=True, + ) + if _json: echo_json(__list_json) From d1b642eb7b9e9b2c7a3e286f7394f375d6359950 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 20 Sep 2019 19:35:55 -0400 Subject: [PATCH 2/3] list improvements --- bake/cli.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/bake/cli.py b/bake/cli.py index 8c27aab..6f374eb 100644 --- a/bake/cli.py +++ b/bake/cli.py @@ -108,8 +108,9 @@ def echo_json(obj): @click.option( "--levels", "-l", - default=1, + default=None, nargs=1, + type=click.INT, help="Lists available tasks (and their dependencies).", ) @click.option( @@ -290,10 +291,14 @@ def entrypoint( if _list: __list_json = {"tasks": {}} - task_list = [] - for _task in bakefile.tasks: - if len(_task.split("/")) <= levels: - task_list.append(_task) + # Enable level filtering. + if levels is not None: + task_list = [] + for _task in bakefile.tasks: + if len(_task.split("/")) <= levels: + task_list.append(_task) + else: + task_list = bakefile.tasks for _task in task_list: depends_on = bakefile[_task].depends_on( @@ -322,9 +327,9 @@ def entrypoint( if not silent: tasks_unechoed = len(bakefile.tasks) - len(task_list) - bake_command = str(click.style(f"bake -l {levels + 1}", fg="red")) + if tasks_unechoed: - # click.echo(err=True) + bake_command = str(click.style(f"bake -l {levels + 1}", fg="red")) click.echo( f"Note: {tasks_unechoed} more tasks are available. " f"Please use $ {bake_command} to see more.", From 1216cc6337eefa026e2560ca57a807b24852b9fe Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 20 Sep 2019 19:38:15 -0400 Subject: [PATCH 3/3] cli improvements --- bake/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bake/cli.py b/bake/cli.py index 6f374eb..36a28a1 100644 --- a/bake/cli.py +++ b/bake/cli.py @@ -111,7 +111,7 @@ def echo_json(obj): default=None, nargs=1, type=click.INT, - help="Lists available tasks (and their dependencies).", + help="List only a given number of '/' levels of tasks.", ) @click.option( "--help", "-h", default=False, is_flag=True, help="Show this message and exit."