Skip to content

Commit 8db6fc1

Browse files
authored
Merge pull request #952 from Debilski/feature/cli-errors
2 parents ce2dcc2 + b01995d commit 8db6fc1

1 file changed

Lines changed: 5 additions & 24 deletions

File tree

pelita/scripts/pelita_main.py

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
import pelita
1616
from pelita.network import PELITA_PORT
17-
# TODO: The check_team option
18-
from pelita.tournament import check_team
1917

2018
from .script_utils import start_logging
2119

@@ -215,8 +213,6 @@ def long_help(s):
215213
metavar='REPLAYFILE', dest='replayfile', const='pelita.dump', nargs='?')
216214
parser.add_argument('--store-output', help=long_help('Write all player’s stdout/stderr to the given folder (must exist)'),
217215
metavar='FOLDER')
218-
parser.add_argument('--check-team', action="store_true",
219-
help=long_help('Check that the team is valid (on first sight) and print its name.'))
220216
parser.add_argument('--append-blue', type=str, metavar='INFO', default=None,
221217
help=long_help('Append info about the blue team (such as group id).'))
222218
parser.add_argument('--append-red', type=str, metavar='INFO', default=None,
@@ -327,22 +323,7 @@ def main():
327323
start_logging(args.log)
328324

329325
if args.rounds < 1:
330-
raise ValueError(f"Must play at least one round (rounds={args.rounds}).")
331-
332-
if args.check_team:
333-
if not args.team_specs:
334-
raise ValueError("No teams specified.")
335-
for team_spec in args.team_specs:
336-
try:
337-
team_name = check_team(team_spec, timeout=args.initial_timeout_length)
338-
print("NAME:", team_name)
339-
except pelita.network.RemotePlayerFailure as e:
340-
if e.error_type == 'ModuleNotFoundError':
341-
#print(f"{e.message}")
342-
pass
343-
else:
344-
raise
345-
sys.exit(0)
326+
parser.error(f"Must play at least one round (rounds={args.rounds}).")
346327

347328
if args.viewer == 'null':
348329
viewers = []
@@ -403,9 +384,9 @@ def main():
403384
if len(team_specs) == 0:
404385
team_specs = ('0', '1')
405386
if len(team_specs) == 1:
406-
raise RuntimeError("Not enough teams given. Must be {}".format(num_teams))
387+
parser.error("Not enough teams given. Must be {}".format(num_teams))
407388
if len(team_specs) > num_teams:
408-
raise RuntimeError("Too many teams given. Must be < {}.".format(num_teams))
389+
parser.error("Too many teams given. Must be < {}.".format(num_teams))
409390

410391
for idx, team_spec in enumerate(team_specs):
411392
if team_spec == "SCAN":
@@ -440,7 +421,7 @@ def main():
440421
layout_string = layout_path.read_text()
441422
layout_dict = pelita.layout.parse_layout(layout_string)
442423
else:
443-
raise FileNotFoundError(f'Layout file "{layout_path}" does not exist.')
424+
parser.error(f'Layout file "{layout_path}" does not exist.')
444425
else:
445426
width, height = args.size
446427

@@ -449,7 +430,7 @@ def main():
449430
elif (width, height) in pelita.game.NFOOD:
450431
trapped_food, total_food = pelita.game.NFOOD[(width, height)]
451432
else:
452-
raise ValueError('--food option must be specified if a custom maze size is set')
433+
parser.error('--food option must be specified if a custom maze size is set')
453434

454435
layout_dict = pelita.maze_generator.generate_maze(trapped_food=trapped_food,
455436
total_food=total_food,

0 commit comments

Comments
 (0)