Skip to content
Myr

Ported naval example from docopt and expanded it

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent a6125e1 · Browse files · 2 files+85 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+85 added−0 removed

  • other:+85 added−0 removed

2 files+85 added−0 removed

added:examples/naval/naval.py+70 added
1import click234@click.group()5@click.version_option()6def cli():7 """Naval Fate.89 This is the docopt example adopted to Click but with some actual10 commands implemented and not just the empty parsing which really11 is not all that interesting.12 """131415@cli.group()16def ship():17 """Manages ships."""181920@ship.command('new')21@click.argument('name')22def ship_new(name):23 """Creates a new ship."""24 click.echo('Created ship %s' % name)252627@ship.command('move')28@click.argument('ship')29@click.argument('x', type=float)30@click.argument('y', type=float)31@click.option('--speed', metavar='KN', default=10,32 help='Speed in knots.')33def ship_move(ship, x, y, speed):34 """Moves SHIP to the new location X,Y."""35 click.echo('Moving ship %s to %s,%s with speed %s' % (ship, x, y, speed))363738@ship.command('shoot')39@click.argument('ship')40@click.argument('x', type=float)41@click.argument('y', type=float)42def ship_shoot(ship, x, y):43 """Makes SHIP fire to X,Y."""44 click.echo('Ship %s fires to %s,%s' % (ship, x, y))454647@cli.group('mine')48def mine(ship):49 """Manages mines."""505152@mine.command('set')53@click.argument('x', type=float)54@click.argument('y', type=float)55@click.option('ty', '--moored', flag_value='moored',56 default=True,57 help='Moored (anchored) mine. Default.')58@click.option('ty', '--drifting', flag_value='drifting',59 help='Drifting mine.')60def mine_set(x, y, ty):61 """Sets a mine at a specific coordinate."""62 click.echo('Set %s mine at %s,%s' % (ty, x, y))636465@mine.command('remove')66@click.argument('x', type=float)67@click.argument('y', type=float)68def mine_remove(x, y):69 """Removes a mine at a specific coordinate."""70 click.echo('Removed mine at %s,%s' % (x, y))
added:examples/naval/setup.py+15 added
1from setuptools import setup23setup(4 name='naval',5 version='2.0',6 py_modules=['naval'],7 include_package_data=True,8 install_requires=[9 'Click',10 ],11 entry_points='''12 [console_scripts]13 naval=naval:cli14 ''',15)