Skip to content

Commit

Permalink
Update help messages in battleship demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
moigagoo committed Jan 14, 2025
1 parent 4671928 commit 0c14794
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions demo/battleship/battleship.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ proc createShip(context: Context): int =
with context:
opt "name", "n":
shipName = val
do:
echo "HINT: to specify the ship name, use `--name|-n=<STRING>` option."

echo fmt"Creating ship {shipName}."

Expand All @@ -21,8 +23,13 @@ proc moveShip(context: Context): int =
with context:
opt "", "x":
x = parseInt(val)
do:
echo "HINT: to specify the x coordinate, use `-x=<NUMBER>` option."

opt "", "y":
y = parseInt(val)
do:
echo "HINT: to specify the y coordinate, use `-y=<NUMBER>` option."

echo fmt"Moving ship: x = {x}, y = {y}."

Expand All @@ -35,20 +42,20 @@ proc turnShip(context: Context): int =
opt "angle", "a":
angle = parseInt(val)
do:
quit("Angle is mandatory", 1)
quit("Angle is mandatory: --angle|-a=<NUMBER>", 1)

flag "counterclockwise", "c":
counterClockWise = true
do:
echo "DEBUG: counterClockWise = false"
echo "HINT: to turn the ship counterclockwise, pass `--counterclockwise|-c` flag."
counterClockWise = false

echo fmt"Turning ship: angle = {angle}, counterclockwise = {counterClockWise}."

proc rootCommand(context: Context): int =
with context:
flag "help", "h":
echo "This is a help string."
echo "Available commands: new, ship move, ship turn."
return 0

flag "version", "v":
Expand Down

0 comments on commit 0c14794

Please sign in to comment.