Browse Source

repl: Fix regex for inventory command

master
Elis Hirwing 3 years ago
parent
commit
fb7d23e655
Signed by: etu GPG Key ID: D57EFA625C9A925F
  1. 6
      repl.php

6
repl.php

@ -4,7 +4,7 @@ require_once('vendor/autoload.php');
echo 'Welcome to the simple REPL for handling stock of items'.PHP_EOL;
echo PHP_EOL;
echo 'Selling usage: S<amount> [item-name]'.PHP_EOL;
echo 'Inventory usage: I<amount> [item-name]'.PHP_EOL;
echo 'Inventory usage: I [item-name]'.PHP_EOL;
echo 'Refilling usage: R<amount> [item-name]'.PHP_EOL;
echo 'Quitting: q'.PHP_EOL;
echo PHP_EOL;
@ -29,7 +29,7 @@ while (true) {
}
// Parse input
preg_match('/^([sir])(\d+)\s?(.+)?$/', $line, $matches);
preg_match('/^([sir])(\d+)?\s?(.+)?$/', $line, $matches);
if (empty($matches)) {
echo 'invalid input'.PHP_EOL;
@ -38,7 +38,7 @@ while (true) {
// Read out fields
$action = $matches[1];
$amount = $matches[2];
$amount = $matches[2] ?? 0;
$item = $matches[3] ?? $defaultItem;
switch ($action) {

Loading…
Cancel
Save