summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2020-03-08 08:57:08 -0700
committerDavid Lord <davidism@gmail.com>2020-03-08 08:57:08 -0700
commit718485be48263056e7036ea9a60ce11b47e2fc26 (patch)
tree0fa1b49ed926f18ab3d247c2cacada892908123a /examples
parentf8f02bfc63cb6e63b7a3373384758f7226553408 (diff)
downloadclick-718485be48263056e7036ea9a60ce11b47e2fc26.tar.gz
manual cleanup
Diffstat (limited to 'examples')
-rw-r--r--examples/aliases/aliases.py6
-rw-r--r--examples/bashcompletion/bashcompletion.py6
-rw-r--r--examples/colors/colors.py8
-rw-r--r--examples/complex/complex/cli.py4
-rw-r--r--examples/imagepipe/imagepipe.py41
-rw-r--r--examples/naval/naval.py2
-rw-r--r--examples/repo/repo.py14
-rw-r--r--examples/termui/termui.py12
-rw-r--r--examples/validation/validation.py10
9 files changed, 54 insertions, 49 deletions
diff --git a/examples/aliases/aliases.py b/examples/aliases/aliases.py
index 1ebad50..250c646 100644
--- a/examples/aliases/aliases.py
+++ b/examples/aliases/aliases.py
@@ -69,7 +69,7 @@ class AliasedGroup(click.Group):
return None
elif len(matches) == 1:
return click.Group.get_command(self, ctx, matches[0])
- ctx.fail("Too many matches: %s" % ", ".join(sorted(matches)))
+ ctx.fail("Too many matches: {}".format(", ".join(sorted(matches))))
def read_config(ctx, param, value):
@@ -125,7 +125,7 @@ def commit():
@pass_config
def status(config):
"""Shows the status."""
- click.echo("Status for %s" % config.path)
+ click.echo("Status for {}".format(config.path))
@cli.command()
@@ -139,4 +139,4 @@ def alias(config, alias_, cmd, config_file):
"""Adds an alias to the specified configuration file."""
config.add_alias(alias_, cmd)
config.write_config(config_file)
- click.echo("Added {} as alias for {}".format(alias_, cmd))
+ click.echo("Added '{}' as alias for '{}'".format(alias_, cmd))
diff --git a/examples/bashcompletion/bashcompletion.py b/examples/bashcompletion/bashcompletion.py
index 636cf64..0502dbc 100644
--- a/examples/bashcompletion/bashcompletion.py
+++ b/examples/bashcompletion/bashcompletion.py
@@ -18,8 +18,8 @@ def get_env_vars(ctx, args, incomplete):
@cli.command(help="A command to print environment variables")
@click.argument("envvar", type=click.STRING, autocompletion=get_env_vars)
def cmd1(envvar):
- click.echo("Environment variable: %s" % envvar)
- click.echo("Value: %s" % os.environ[envvar])
+ click.echo("Environment variable: {}".format(envvar))
+ click.echo("Value: {}".format(os.environ[envvar]))
@click.group(help="A group that holds a subcommand")
@@ -39,7 +39,7 @@ def list_users(ctx, args, incomplete):
@group.command(help="Choose a user")
@click.argument("user", type=click.STRING, autocompletion=list_users)
def subcmd(user):
- click.echo("Chosen user is %s" % user)
+ click.echo("Chosen user is {}".format(user))
cli.add_command(group)
diff --git a/examples/colors/colors.py b/examples/colors/colors.py
index 4219c0f..012538d 100644
--- a/examples/colors/colors.py
+++ b/examples/colors/colors.py
@@ -30,12 +30,14 @@ def cli():
Give it a try!
"""
for color in all_colors:
- click.echo(click.style("I am colored %s" % color, fg=color))
+ click.echo(click.style("I am colored {}".format(color), fg=color))
for color in all_colors:
- click.echo(click.style("I am colored %s and bold" % color, fg=color, bold=True))
+ click.echo(
+ click.style("I am colored {} and bold".format(color), fg=color, bold=True)
+ )
for color in all_colors:
click.echo(
- click.style("I am reverse colored %s" % color, fg=color, reverse=True)
+ click.style("I am reverse colored {}".format(color), fg=color, reverse=True)
)
click.echo(click.style("I am blinking", blink=True))
diff --git a/examples/complex/complex/cli.py b/examples/complex/complex/cli.py
index 5e75f58..c539fe8 100644
--- a/examples/complex/complex/cli.py
+++ b/examples/complex/complex/cli.py
@@ -41,7 +41,9 @@ class ComplexCLI(click.MultiCommand):
try:
if sys.version_info[0] == 2:
name = name.encode("ascii", "replace")
- mod = __import__("complex.commands.cmd_" + name, None, None, ["cli"])
+ mod = __import__(
+ "complex.commands.cmd_{}".format(name), None, None, ["cli"]
+ )
except ImportError:
return
return mod.cli
diff --git a/examples/imagepipe/imagepipe.py b/examples/imagepipe/imagepipe.py
index 5e34405..d46c33f 100644
--- a/examples/imagepipe/imagepipe.py
+++ b/examples/imagepipe/imagepipe.py
@@ -89,7 +89,7 @@ def open_cmd(images):
"""
for image in images:
try:
- click.echo('Opening "%s"' % image)
+ click.echo("Opening '{}'".format(image))
if image == "-":
img = Image.open(click.get_binary_stdin())
img.filename = "-"
@@ -97,13 +97,13 @@ def open_cmd(images):
img = Image.open(image)
yield img
except Exception as e:
- click.echo('Could not open image "{}": {}'.format(image, e), err=True)
+ click.echo("Could not open image '{}': {}".format(image, e), err=True)
@cli.command("save")
@click.option(
"--filename",
- default="processed-%04d.png",
+ default="processed-{:04}.png",
type=click.Path(),
help="The format for the filename.",
show_default=True,
@@ -113,12 +113,12 @@ def save_cmd(images, filename):
"""Saves all processed images to a series of files."""
for idx, image in enumerate(images):
try:
- fn = filename % (idx + 1)
- click.echo('Saving "{}" as "{}"'.format(image.filename, fn))
+ fn = filename.format(idx + 1)
+ click.echo("Saving '{}' as '{}'".format(image.filename, fn))
yield image.save(fn)
except Exception as e:
click.echo(
- 'Could not save image "{}": {}'.format(image.filename, e), err=True
+ "Could not save image '{}': {}".format(image.filename, e), err=True
)
@@ -127,7 +127,7 @@ def save_cmd(images, filename):
def display_cmd(images):
"""Opens all images in an image viewer."""
for image in images:
- click.echo('Displaying "%s"' % image.filename)
+ click.echo("Displaying '{}'".format(image.filename))
image.show()
yield image
@@ -142,7 +142,7 @@ def resize_cmd(images, width, height):
"""
for image in images:
w, h = (width or image.size[0], height or image.size[1])
- click.echo('Resizing "%s" to %dx%d' % (image.filename, w, h))
+ click.echo("Resizing '{}' to {}x{}".format(image.filename, w, h))
image.thumbnail((w, h))
yield image
@@ -160,7 +160,7 @@ def crop_cmd(images, border):
if border is not None:
for idx, val in enumerate(box):
box[idx] = max(0, val - border)
- click.echo('Cropping "%s" by %dpx' % (image.filename, border))
+ click.echo("Cropping '{}' by {}px".format(image.filename, border))
yield copy_filename(image.crop(box), image)
else:
yield image
@@ -176,7 +176,7 @@ def convert_rotation(ctx, param, value):
return (Image.ROTATE_180, 180)
if value in ("-90", "270", "l", "left"):
return (Image.ROTATE_270, 270)
- raise click.BadParameter('invalid rotation "%s"' % value)
+ raise click.BadParameter("invalid rotation '{}'".format(value))
def convert_flip(ctx, param, value):
@@ -187,7 +187,7 @@ def convert_flip(ctx, param, value):
return (Image.FLIP_LEFT_RIGHT, "left to right")
if value in ("tb", "topbottom", "upsidedown", "ud"):
return (Image.FLIP_LEFT_RIGHT, "top to bottom")
- raise click.BadParameter('invalid flip "%s"' % value)
+ raise click.BadParameter("invalid flip '{}'".format(value))
@cli.command("transpose")
@@ -201,11 +201,11 @@ def transpose_cmd(images, rotate, flip):
for image in images:
if rotate is not None:
mode, degrees = rotate
- click.echo('Rotate "%s" by %ddeg' % (image.filename, degrees))
+ click.echo("Rotate '{}' by {}deg".format(image.filename, degrees))
image = copy_filename(image.transpose(mode), image)
if flip is not None:
mode, direction = flip
- click.echo('Flip "{}" {}'.format(image.filename, direction))
+ click.echo("Flip '{}' {}".format(image.filename, direction))
image = copy_filename(image.transpose(mode), image)
yield image
@@ -217,7 +217,7 @@ def blur_cmd(images, radius):
"""Applies gaussian blur."""
blur = ImageFilter.GaussianBlur(radius)
for image in images:
- click.echo('Blurring "%s" by %dpx' % (image.filename, radius))
+ click.echo("Blurring '{}' by {}px".format(image.filename, radius))
yield copy_filename(image.filter(blur), image)
@@ -234,8 +234,9 @@ def smoothen_cmd(images, iterations):
"""Applies a smoothening filter."""
for image in images:
click.echo(
- 'Smoothening "%s" %d time%s'
- % (image.filename, iterations, iterations != 1 and "s" or "",)
+ "Smoothening '{}' {} time{}".format(
+ image.filename, iterations, "s" if iterations != 1 else ""
+ )
)
for _ in range(iterations):
image = copy_filename(image.filter(ImageFilter.BLUR), image)
@@ -247,7 +248,7 @@ def smoothen_cmd(images, iterations):
def emboss_cmd(images):
"""Embosses an image."""
for image in images:
- click.echo('Embossing "%s"' % image.filename)
+ click.echo("Embossing '{}'".format(image.filename))
yield copy_filename(image.filter(ImageFilter.EMBOSS), image)
@@ -259,7 +260,7 @@ def emboss_cmd(images):
def sharpen_cmd(images, factor):
"""Sharpens an image."""
for image in images:
- click.echo('Sharpen "{}" by {:f}'.format(image.filename, factor))
+ click.echo("Sharpen '{}' by {}".format(image.filename, factor))
enhancer = ImageEnhance.Sharpness(image)
yield copy_filename(enhancer.enhance(max(1.0, factor)), image)
@@ -281,12 +282,12 @@ def paste_cmd(images, left, right):
yield image
return
- click.echo('Paste "{}" on "{}"'.format(to_paste.filename, image.filename))
+ click.echo("Paste '{}' on '{}'".format(to_paste.filename, image.filename))
mask = None
if to_paste.mode == "RGBA" or "transparency" in to_paste.info:
mask = to_paste
image.paste(to_paste, (left, right), mask)
- image.filename += "+" + to_paste.filename
+ image.filename += "+{}".format(to_paste.filename)
yield image
for image in imageiter:
diff --git a/examples/naval/naval.py b/examples/naval/naval.py
index a77dea8..b8d31e1 100644
--- a/examples/naval/naval.py
+++ b/examples/naval/naval.py
@@ -21,7 +21,7 @@ def ship():
@click.argument("name")
def ship_new(name):
"""Creates a new ship."""
- click.echo("Created ship %s" % name)
+ click.echo("Created ship {}".format(name))
@ship.command("move")
diff --git a/examples/repo/repo.py b/examples/repo/repo.py
index 470296b..5fd6ead 100644
--- a/examples/repo/repo.py
+++ b/examples/repo/repo.py
@@ -17,7 +17,7 @@ class Repo(object):
click.echo(" config[{}] = {}".format(key, value), file=sys.stderr)
def __repr__(self):
- return "<Repo %r>" % self.home
+ return "<Repo {}>".format(self.home)
pass_repo = click.make_pass_decorator(Repo)
@@ -82,7 +82,7 @@ def clone(repo, src, dest, shallow, rev):
repo.home = dest
if shallow:
click.echo("Making shallow checkout")
- click.echo("Checking out revision %s" % rev)
+ click.echo("Checking out revision {}".format(rev))
@cli.command()
@@ -93,7 +93,7 @@ def delete(repo):
This will throw away the current repository.
"""
- click.echo("Destroying repo %s" % repo.home)
+ click.echo("Destroying repo {}".format(repo.home))
click.echo("Deleted!")
@@ -118,8 +118,8 @@ def setuser(repo, username, email, password):
"--message",
"-m",
multiple=True,
- help="The commit message. If provided multiple times each "
- "argument gets converted into a new line.",
+ help="The commit message. If provided multiple times each"
+ " argument gets converted into a new line.",
)
@click.argument("files", nargs=-1, type=click.Path())
@pass_repo
@@ -136,7 +136,7 @@ def commit(repo, files, message):
marker = "# Files to be committed:"
hint = ["", "", marker, "#"]
for file in files:
- hint.append("# U %s" % file)
+ hint.append("# U {}".format(file))
message = click.edit("\n".join(hint))
if message is None:
click.echo("Aborted!")
@@ -148,7 +148,7 @@ def commit(repo, files, message):
else:
msg = "\n".join(message)
click.echo("Files to be committed: {}".format(files))
- click.echo("Commit message:\n" + msg)
+ click.echo("Commit message:\n{}".format(msg))
@cli.command(short_help="Copies files.")
diff --git a/examples/termui/termui.py b/examples/termui/termui.py
index 2af114d..7b3da43 100644
--- a/examples/termui/termui.py
+++ b/examples/termui/termui.py
@@ -16,8 +16,8 @@ def cli():
def colordemo():
"""Demonstrates ANSI color support."""
for color in "red", "green", "blue":
- click.echo(click.style("I am colored %s" % color, fg=color))
- click.echo(click.style("I am background colored %s" % color, bg=color))
+ click.echo(click.style("I am colored {}".format(color), fg=color))
+ click.echo(click.style("I am background colored {}".format(color), bg=color))
@cli.command()
@@ -25,7 +25,7 @@ def pager():
"""Demonstrates using the pager."""
lines = []
for x in range(200):
- lines.append("%s. Hello World!" % click.style(str(x), fg="green"))
+ lines.append("{}. Hello World!".format(click.style(str(x), fg="green")))
click.echo_via_pager("\n".join(lines))
@@ -56,7 +56,7 @@ def progress(count):
def show_item(item):
if item is not None:
- return "Item #%d" % item
+ return "Item #{}".format(item)
with click.progressbar(
filter(items),
@@ -119,13 +119,13 @@ def locate(url):
def edit():
"""Opens an editor with some text in it."""
MARKER = "# Everything below is ignored\n"
- message = click.edit("\n\n" + MARKER)
+ message = click.edit("\n\n{}".format(MARKER))
if message is not None:
msg = message.split(MARKER, 1)[0].rstrip("\n")
if not msg:
click.echo("Empty message!")
else:
- click.echo("Message:\n" + msg)
+ click.echo("Message:\n{}".format(msg))
else:
click.echo("You did not enter anything!")
diff --git a/examples/validation/validation.py b/examples/validation/validation.py
index 9abb125..c4f7352 100644
--- a/examples/validation/validation.py
+++ b/examples/validation/validation.py
@@ -20,8 +20,8 @@ class URL(click.ParamType):
value = urlparse.urlparse(value)
if value.scheme not in ("http", "https"):
self.fail(
- "invalid URL scheme (%s). Only HTTP URLs are "
- "allowed" % value.scheme,
+ "invalid URL scheme ({}). Only HTTP URLs are"
+ " allowed".format(value.scheme),
param,
ctx,
)
@@ -47,6 +47,6 @@ def cli(count, foo, url):
'If a value is provided it needs to be the value "wat".',
param_hint=["--foo"],
)
- click.echo("count: %s" % count)
- click.echo("foo: %s" % foo)
- click.echo("url: %s" % repr(url))
+ click.echo("count: {}".format(count))
+ click.echo("foo: {}".format(foo))
+ click.echo("url: {!r}".format(url))