addArgument('action', InputArgument::OPTIONAL, 'list, add or remove', 'list') ->addArgument('name', InputArgument::OPTIONAL, 'the room'); } protected function execute(InputInterface $input, OutputInterface $output): int { $store = new RoomStore($this->data . '/rooms.json'); $action = (string)$input->getArgument('action'); $name = trim((string)$input->getArgument('name')); if ($action === 'list') { foreach ($store->load() as $room) { $output->writeln($room->name); } return Command::SUCCESS; } if (!in_array($action, ['add', 'remove'], true) || $name === '') { $output->writeln('Usage: rooms [list] | rooms add "Name" | rooms remove "Name"'); return Command::INVALID; } $changed = $store->edit($name, $action === 'add'); $output->writeln($changed ? ($action === 'add' ? "Room \"$name\" added." : "Room \"$name\" removed.") : "Nothing to do for \"$name\"."); return Command::SUCCESS; } }