Skip to content

Commit

Permalink
Add --verbose option
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed Oct 7, 2019
1 parent a00d71d commit 5c620cd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
9 changes: 6 additions & 3 deletions bake/bakefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def _transform_line(line, *, indent_styles=INDENT_STYLES):

return line

def gen_source(self, *, sources):
def gen_source(self, *, sources, verbose=False):

source_container = []

Expand All @@ -519,6 +519,9 @@ def gen_source(self, *, sources):

source_container += [self.bashfile.funcs_source, self.bashfile.root_source]

if verbose and Bakefile._is_safe_to_inject(shebang):
yield "set -x"

main_source = "\n".join(source_container)

for sourceline in main_source.split("\n"):
Expand All @@ -529,7 +532,7 @@ def gen_source(self, *, sources):
yield "\n"

def execute(
self, *, blocking=False, debug=False, interactive=False, silent=False, **kwargs
self, *, blocking=False, debug=False, interactive=False, silent=False, verbose=False, **kwargs
):

args = " ".join([shlex_quote(a) for a in self.bf.args])
Expand All @@ -539,7 +542,7 @@ def execute(
)

script = (
f"t=$(mktemp) && bake --source {self.name} "
f"t=$(mktemp) && bake {'--verbose' if verbose else ''} --source {self.name} "
"> ${t} && chmod +x ${t} && ${t} "
+ f"{args} "
+ f"{sed_magic} "
Expand Down
5 changes: 4 additions & 1 deletion bake/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def echo_json(obj):
)
@click.option("--debug", default=False, is_flag=True, hidden=True)
@click.option("--source", default=False, nargs=1, hidden=True)
@click.option("--verbose", default=False, is_flag=True)
@click.option(
"--allow",
default=False,
Expand Down Expand Up @@ -200,6 +201,7 @@ def entrypoint(
yes,
help,
source,
verbose,
):
"""bake — the strangely familiar task–runner."""

Expand Down Expand Up @@ -249,7 +251,7 @@ def entrypoint(
if source:

task = bf.tasks[source]
source = task.gen_source(sources=[task.bf.root_source, task.source])
source = task.gen_source(sources=[task.bf.root_source, task.source], verbose=verbose)

for source_line in source:
click.echo(source_line)
Expand Down Expand Up @@ -391,6 +393,7 @@ def execute_task(task, *, silent=False):
debug=debug,
silent=silent,
interactive=force_interactive or interactive,
verbose=verbose,
)

if not _continue:
Expand Down
6 changes: 6 additions & 0 deletions tests/basics.bats
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ export BAKEFILE=basics.Bakefile
run bake deps/fail --no-deps
[ "${status}" -eq 0 ]
}

@test "bake --verbose" {
run pipenv run bake --verbose echo foo
[ "${lines[0]}" = " + Executing echo:" ]
[ "${lines[1]}" = " | + echo foo" ]
}

0 comments on commit 5c620cd

Please sign in to comment.