Skip to content
Myr

naval.py

This file

Path

examples/naval/naval.py

72 lines · 1.7 KiB · Python

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than 9ce34f2 point at it.

Make faqs section. Add the first question about windows shell expansion. (#2927)Rowlando13before adoption9ce34f2

lines 1–72why, one step back
1import click
234@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(f"Created ship {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, help="Speed in knots.")32def ship_move(ship, x, y, speed):33 """Moves SHIP to the new location X,Y."""34 click.echo(f"Moving ship {ship} to {x},{y} with speed {speed}")353637@ship.command("shoot")38@click.argument("ship")39@click.argument("x", type=float)40@click.argument("y", type=float)41def ship_shoot(ship, x, y):42 """Makes SHIP fire to X,Y."""43 click.echo(f"Ship {ship} fires to {x},{y}")444546@cli.group("mine")47def mine():48 """Manages mines."""495051@mine.command("set")52@click.argument("x", type=float)53@click.argument("y", type=float)54@click.option(55 "ty",56 "--moored",57 flag_value="moored",58 default=True,59 help="Moored (anchored) mine. Default.",60)61@click.option("ty", "--drifting", flag_value="drifting", help="Drifting mine.")62def mine_set(x, y, ty):63 """Sets a mine at a specific coordinate."""64 click.echo(f"Set {ty} mine at {x},{y}")656667@mine.command("remove")68@click.argument("x", type=float)69@click.argument("y", type=float)70def mine_remove(x, y):71 """Removes a mine at a specific coordinate."""72 click.echo(f"Removed mine at {x},{y}")