naval.py
This file
Path
examples/naval/naval.py
72 lines · 1.7 KiB · Python
Last changed by
Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
History of this fileTake it
The walk stopped after 200 commits: lines older than 5210849 point at it.
Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 1–19why, one step back1import 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."""1819Merge branch '7.x'David Lordbefore adoption7239794
lines 20–21why, one step back20@ship.command("new")21@click.argument("name")Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 22–23why, one step back22def ship_new(name):23 """Creates a new ship."""Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 24why, one step back24 click.echo(f"Created ship {name}")Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 25–26why, one step back2526Merge branch '7.x'David Lordbefore adoption7239794
lines 27–31why, one step back27@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.")Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 32–33why, one step back32def ship_move(ship, x, y, speed):33 """Moves SHIP to the new location X,Y."""Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 34why, one step back34 click.echo(f"Moving ship {ship} to {x},{y} with speed {speed}")Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 35–36why, one step back3536Merge branch '7.x'David Lordbefore adoption7239794
lines 37–40why, one step back37@ship.command("shoot")38@click.argument("ship")39@click.argument("x", type=float)40@click.argument("y", type=float)Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 41–42why, one step back41def ship_shoot(ship, x, y):42 """Makes SHIP fire to X,Y."""Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 43why, one step back43 click.echo(f"Ship {ship} fires to {x},{y}")Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 44–45why, one step back4445Merge branch '7.x'David Lordbefore adoption7239794
line 46why, one step back46@cli.group("mine")Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 47–50why, one step back47def mine():48 """Manages mines."""4950Merge branch '7.x'David Lordbefore adoption7239794
lines 51–61why, one step back51@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.")Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 62–63why, one step back62def mine_set(x, y, ty):63 """Sets a mine at a specific coordinate."""Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 64why, one step back64 click.echo(f"Set {ty} mine at {x},{y}")Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 65–66why, one step back6566Merge branch '7.x'David Lordbefore adoption7239794
lines 67–69why, one step back67@mine.command("remove")68@click.argument("x", type=float)69@click.argument("y", type=float)Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 70–71why, one step back70def mine_remove(x, y):71 """Removes a mine at a specific coordinate."""Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 72why, one step back72 click.echo(f"Removed mine at {x},{y}")