Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --verbose option #22

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 10 additions & 1 deletion bake/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ 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,
hidden=False,
help="Run verbosely",
)
@click.option(
"--allow",
default=False,
Expand Down Expand Up @@ -200,6 +207,7 @@ def entrypoint(
yes,
help,
source,
verbose,
):
"""bake — the strangely familiar task–runner."""

Expand Down Expand Up @@ -249,7 +257,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 +399,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 bake --verbose echo foo
[ "${lines[0]}" = " + Executing echo:" ]
[ "${lines[1]}" = " | + echo foo" ]
}