-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathnaval.py
66 lines (47 loc) · 1.75 KB
/
naval.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import click
from click_aliases import ClickAliasedGroup
@click.group(cls=ClickAliasedGroup)
def cli():
"""Naval Fate."""
@cli.group("ship", cls=ClickAliasedGroup, aliases=["boat"])
def fleet():
"""Manages ships."""
@fleet.command("new", aliases=["create", "add", "build"])
@click.argument("name")
def ship_new(name):
"""Creates a new ship."""
click.echo("Created ship %s" % name)
@fleet.command("move", aliases=["float", "navigate"])
@click.argument("ship")
@click.argument("x", type=float)
@click.argument("y", type=float)
@click.option("--speed", metavar="KN", default=10, help="Speed in knots.")
def ship_move(ship, x, y, speed):
"""Moves SHIP to the new location X,Y."""
click.echo(f"Moving ship {ship} to {x},{y} with speed {speed}")
@fleet.command("shoot", aliases=["fire"])
@click.argument("ship")
@click.argument("x", type=float)
@click.argument("y", type=float)
def ship_shoot(ship, x, y):
"""Makes SHIP fire to X,Y."""
click.echo(f"Ship {ship} fires to {x},{y}")
@cli.group("mine", cls=ClickAliasedGroup, aliases=["bomb"])
def mine():
"""Manages mines."""
@mine.command("set")
@click.argument("x", type=float)
@click.argument("y", type=float)
@click.option("ty", "--moored", flag_value="moored", default=True, help="Moored (anchored) mine. Default.")
@click.option("ty", "--drifting", flag_value="drifting", help="Drifting mine.")
def mine_set(x, y, ty):
"""Sets a mine at a specific coordinate."""
click.echo(f"Set {ty} mine at {x},{y}")
@mine.command("remove", aliases=["rm", "delete", "remove"])
@click.argument("x", type=float)
@click.argument("y", type=float)
def mine_remove(x, y):
"""Removes a mine at a specific coordinate."""
click.echo(f"Removed mine at {x},{y}")
if __name__ == "__main__":
cli()