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
Provenance
Commit
ae52b1a
Tree
0d231ad
Author
Armin Ronacher <armin.ronacher@active-4.com>
Committer
Armin Ronacher <armin.ronacher@active-4.com>
Parent
a6125e1
2 files changed+85 added−0 removed
added:examples/naval/naval.py+70 added
1+import click2+3+4+@click.group()5+@click.version_option()6+def cli():7+ """Naval Fate.8+9+ 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+ """13+14+15+@cli.group()16+def ship():17+ """Manages ships."""18+19+20+@ship.command('new')21+@click.argument('name')22+def ship_new(name):23+ """Creates a new ship."""24+ click.echo('Created ship %s' % name)25+26+27+@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.')33+def 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))36+37+38+@ship.command('shoot')39+@click.argument('ship')40+@click.argument('x', type=float)41+@click.argument('y', type=float)42+def ship_shoot(ship, x, y):43+ """Makes SHIP fire to X,Y."""44+ click.echo('Ship %s fires to %s,%s' % (ship, x, y))45+46+47+@cli.group('mine')48+def mine(ship):49+ """Manages mines."""50+51+52+@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.')60+def 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))63+64+65+@mine.command('remove')66+@click.argument('x', type=float)67+@click.argument('y', type=float)68+def mine_remove(x, y):69+ """Removes a mine at a specific coordinate."""70+ click.echo('Removed mine at %s,%s' % (x, y))