Skip to content
Myr

naval.py

This file

Path

examples/naval/naval.py

70 lines · 1.7 KiB · Python

Last changed by

Not known.

History of this file

Take it

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():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))