This commit is contained in:
2019-09-22 23:00:25 -04:00
parent aba0ec155e
commit b70a69b422
7 changed files with 96 additions and 13 deletions
+15 -2
View File
@@ -58,11 +58,24 @@ ci: ci/setup
ci/setup: @skip:key=Pipfile.lock
pipenv install --dev --deploy --system
random/python:
random/ip:
#!/usr/bin/env python
import requests
print(requests)
r = requests.get('https://httpbin.org/ip')
print(r.json()['origin'].split(',')[0])
random/clis:
bake:red 'Testing subcommands.'
bake:step 'sub-task'
echo 'I should *not* be red.' | bake:red | bake:indent | bake:redless
echo 'I *should* be red.' | bake:red --always | bake:indent
echo "$(echo test $(bake:red test) test | bake:indent)"
echo
random/kr:
sparkescakesparkles="✨ 🍰 ✨" | pbcopy
echo "$sparkescakesparkles" | pbcopy
echo 'KR Copied!' | bake:red --fg cyan
lazy_brew() {
set -e
+2
View File
@@ -1 +1,3 @@
from . import red
from . import indent
from . import step
+6 -6
View File
@@ -4,17 +4,17 @@ import click
@click.command(context_settings=dict(help_option_names=["-h", "--help"]))
@click.option(
"--only-stdout", is_flag=True, type=click.BOOL, default=False, help="Use stdout."
)
@click.option(
"--read-stderr", is_flag=True, type=click.BOOL, default=True, help="Read stderr."
)
@click.option("--char", nargs=1, type=click.STRING, default="|", help="Prefix char.")
def indent(*, char, read_stderr, only_stdout):
def entrypoint(*, char, read_stderr):
pipe = sys.stdin if not read_stderr else sys.stderr
for line in pipe:
click.echo(f" {char} ", err=(not only_stdout), nl=False)
click.echo(line, nl=False)
if line:
print(f" {char} ", end="")
print(line.rstrip())
else:
print(f" {char} ", end="")
+19 -3
View File
@@ -1,11 +1,19 @@
import sys
import click
import colorama
@click.command(context_settings=dict(help_option_names=["-h", "--help"]))
@click.argument("s", type=click.STRING, default=False, required=False)
@click.option("--err", is_flag=True, type=click.BOOL, default=False, help="Use stderr.")
@click.option(
"--always",
is_flag=True,
type=click.BOOL,
default=False,
help="Always speak technicolor.",
)
@click.option(
"--fg", nargs=1, type=click.STRING, default="red", help="Foreground color to use."
)
@@ -17,11 +25,19 @@ import click
help="Background color to use (rare).",
)
@click.option("--bold", is_flag=True, type=click.BOOL, default=False, help="Be bold.")
def red(s, *, fg, bg, bold, err):
def entrypoint(s, *, fg, bg, bold, err, always):
if always:
# Don't strip colors.
colorama.init(strip=False)
if s is False:
s = sys.stdin.read()
s = s.rstrip()
try:
click.echo(click.style(s, fg=fg, bg=bg), err=err, nl=False)
s = click.style(s, fg=fg, bg=bg)
except TypeError:
click.echo(click.style(s), err=err, nl=False)
pass
print(s)
+16
View File
@@ -0,0 +1,16 @@
import sys
import click
@click.command(context_settings=dict(help_option_names=["-h", "--help"]))
@click.argument("s", type=click.STRING, default=False, required=False)
@click.option("--err", is_flag=True, type=click.BOOL, default=False, help="Use stderr.")
def entrypoint(s, *, err):
if s is False:
s = sys.stdin.read()
s = s.rstrip()
click.echo(s)
+33
View File
@@ -0,0 +1,33 @@
# + Executing random/entrypoints:
import sys
import colorama
import click
# Don't strip colors.
colorama.init(strip=False)
@click.command(context_settings=dict(help_option_names=["-h", "--help"]))
@click.argument("s", type=click.STRING, default=False, required=False)
@click.option(
"--read-stderr", is_flag=True, type=click.BOOL, default=True, help="Read stderr."
)
@click.option("--char", nargs=1, type=click.STRING, default="+", help="Prefix char.")
@click.option(
"--color", nargs=1, type=click.STRING, default="yellow", help="Color to use."
)
def entrypoint(s, *, char, read_stderr, color):
pipe = sys.stdin if not read_stderr else sys.stderr
if s is False:
s = pipe.read()
for line in s.strip().split("\n"):
try:
title = str(click.style(line, fg=color))
except TypeError:
title = line
print(f" + {title}: ")
+5 -2
View File
@@ -106,8 +106,10 @@ setup(
entry_points={
"console_scripts": [
"bake=bake.cli:entrypoint",
"bake:red=bake.scripts.red:red",
"bake:indent=bake.scripts.indent:indent",
"bake:red=bake.scripts.red:entrypoint",
"bake:redless=bake.scripts.redless:entrypoint",
"bake:indent=bake.scripts.indent:entrypoint",
"bake:step=bake.scripts.step:entrypoint",
]
},
install_requires=REQUIRED,
@@ -121,6 +123,7 @@ setup(
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
],