From 9097f7dc1f4c8bd816d9695a22397764de7e5ddc Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 15 Sep 2019 13:33:30 -0400 Subject: [PATCH] caps lock --- .gitignore | 1 + Bashfile | 30 ++++++++++++++++++++------ README.md | 41 ++++++++++++++++++++++++++++++------ bake/bakefile.py | 9 +++++--- bake/cli.py | 18 +++++++++------- node_modules/.yarn-integrity | 12 +++++++++++ yarn.lock | 4 ++++ 7 files changed, 91 insertions(+), 24 deletions(-) create mode 100644 node_modules/.yarn-integrity create mode 100644 yarn.lock diff --git a/.gitignore b/.gitignore index eb43cce..d4bbb99 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode/settings.json bake.egg-info/* +**/__pycache__/** diff --git a/Bashfile b/Bashfile index 3da5007..ac56374 100644 --- a/Bashfile +++ b/Bashfile @@ -1,7 +1,25 @@ -hello: - set -eu pipefail - echo hello $HELLO -env: - env -argv: +echo: + cat Bakefile +format: + black . + +full-install: system-deps install +install: node-deps python-deps + + +argv-example: + set -eux + echo "HELLO, $WHO" echo $@ + +dangerous-example: @confirm:secure + rm -fr * + +python-deps: + # Example of comments + pipenv install +node-deps: + yarn install + +system-deps: + brew install pipenv diff --git a/README.md b/README.md index 263062a..0fe417d 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,10 @@ I love using `Makefile`s for one-off tasks in projects. The problem with doing t ## Example `Bakefile`, for use with `bake`: ```make -echo: - cat Bakefile -format: - black . - full-install: system-deps install install: node-deps python-deps - +format: + black . argv-example: set -eux @@ -26,10 +22,11 @@ argv-example: echo $@ dangerous-example: @confirm:secure + # This will make you do a + # simple math question before proceeding. rm -fr * python-deps: - # Example of comments pipenv install node-deps: yarn install @@ -38,6 +35,36 @@ system-deps: brew install pipenv ``` +**Running the above `Bakefile`**: + +```shell +$ bake --silent format +All done! โœจ ๐Ÿฐ โœจ +7 files left unchanged. + +$ bake install + ยท Executing 'node-deps': +yarn install v1.17.3 +[1/4] ๐Ÿ” Resolving packages... +success Already up-to-date. +โœจ Done in 0.03s. + ยท Executing 'python-deps': +Installing dependencies from Pipfile.lock (2ee04c)โ€ฆ + ๐Ÿ โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰ 8/8 โ€” 00:00:01 + ยท Done. + +$ bake argv-example WHO=you 1 2 3 + ยท Executing 'argv-example': +++ echo 'HELLO, you' +HELLO, you +++ echo '[1,' 2, '3]' +[1, 2, 3] + ยท Done. + +$ bake dangerous-example +ยท Executing '@confirm:secure' ยท + What is 10 times 2?: + ## Features - a `Bakefile`, which looks and feels like the good parts of a `Makefile`. diff --git a/bake/bakefile.py b/bake/bakefile.py index b3b785a..9a32769 100644 --- a/bake/bakefile.py +++ b/bake/bakefile.py @@ -71,7 +71,7 @@ class TaskFilter: def execute(self, yes=False, **kwargs): if self.name == "confirm": - self.execute_confirm(yes=yes, **self.args) + self.execute_confirm(yes=yes, **self.arguments) class TaskScript: @@ -137,7 +137,7 @@ class TaskScript: if line.startswith(indent_style): return line[len(indent_style) :] - def execute(self, *, blocking=False, debug=False, **kwargs): + def execute(self, *, blocking=False, debug=False, silent=False, **kwargs): from tempfile import mkstemp import stat from shlex import quote as shlex_quote @@ -155,7 +155,10 @@ class TaskScript: args = [shlex_quote(a) for a in self.bashfile.args] - script = shlex_quote(f"unbuffer {tf} {args} 2>&1 | bashf-indent") + if silent: + script = shlex_quote(f"{tf} {args}") + else: + script = shlex_quote(f"{tf} {args}") cmd = f"bash --init-file {shlex_quote(stdlib_path)} -i -c {script} " if debug: diff --git a/bake/cli.py b/bake/cli.py index 2860916..a36a49d 100644 --- a/bake/cli.py +++ b/bake/cli.py @@ -49,7 +49,6 @@ def indent(line): ) @click.option( "--secure", - "-s", is_flag=True, type=click.BOOL, help="Ignore parent shell's environment variables.", @@ -62,7 +61,7 @@ def indent(line): # help="task ARGV argument (can be passed multiple times).", ) @click.option("--no-color", is_flag=True, type=click.BOOL, help="Disable colors.") -@click.option("--quiet", "-q", is_flag=True, type=click.BOOL, help="Reduce output.") +@click.option("--silent", "-s", is_flag=True, type=click.BOOL, help="Reduce output.") @click.option( "--environ-json", "-j", @@ -80,7 +79,7 @@ def task( environ_json, shellcheck, debug, - quiet, + silent, secure, no_color, whitelist, @@ -150,14 +149,14 @@ def task( click.echo(crayons.red(f"Task {task} does not exist!")) sys.exit(1) - def execute_task(task, *, next_task=None): - if not quiet: + def execute_task(task, *, next_task=None, silent=False): + if not silent: click.echo( crayons.white(" ยท ") + crayons.yellow(f"Executing {task}") + crayons.white(" ยท ") ) - return_code = task.execute(yes=yes, next_task=next_task) + return_code = task.execute(yes=yes, next_task=next_task, silent=silent) if fail: if not return_code == 0: @@ -171,9 +170,12 @@ def task( except IndexError: next_task = None - execute_task(task, next_task=next_task) + execute_task(task, next_task=next_task, silent=silent) - click.echo(crayons.white(" ยท ") + crayons.green("Done") + crayons.white(" ยท ")) + if not silent: + click.echo( + crayons.white(" ยท ") + crayons.green("Done") + crayons.white(" ยท ") + ) sys.exit(0) diff --git a/node_modules/.yarn-integrity b/node_modules/.yarn-integrity new file mode 100644 index 0000000..95a7b70 --- /dev/null +++ b/node_modules/.yarn-integrity @@ -0,0 +1,12 @@ +{ + "systemParams": "darwin-x64-64", + "modulesFolders": [ + "node_modules" + ], + "flags": [], + "linkedModules": [], + "topLevelPatterns": [], + "lockfileEntries": {}, + "files": [], + "artifacts": {} +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..fb57ccd --- /dev/null +++ b/yarn.lock @@ -0,0 +1,4 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + +