File: cli.py

package info (click to toggle)
python-click-plugins 1.1.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 204 kB
  • sloc: python: 308; makefile: 8
file content (49 lines) | stat: -rw-r--r-- 893 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Commandline interface for PrintIt
"""


from pkg_resources import iter_entry_points

import click
from click_plugins import with_plugins


@with_plugins(iter_entry_points('printit.plugins'))
@click.group()
def cli():

    """
    Format and print file contents.

    \b
    For example:
    \b
        $ cat README.rst | printit lower
    """


@cli.command()
@click.argument('infile', type=click.File('r'), default='-')
@click.argument('outfile', type=click.File('w'), default='-')
def upper(infile, outfile):

    """
    Convert to upper case.
    """

    for line in infile:
        outfile.write(line.upper())


@cli.command()
@click.argument('infile', type=click.File('r'), default='-')
@click.argument('outfile', type=click.File('w'), default='-')
def lower(infile, outfile):

    """
    Convert to lower case.
    """

    for line in infile:
        outfile.write(line.lower())