Browse Source

repl: Handle input

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

25
repl.php

@ -21,4 +21,29 @@ while (true) {
if ($line === 'q') {
break;
}
// Parse input
preg_match('/^([sir])(\d+)\s?(.+)?$/', $line, $matches);
if (empty($matches)) {
echo 'invalid input'.PHP_EOL;
continue;
}
// Read out fields
$action = $matches[1];
$amount = $matches[2];
$item = $matches[3] ?? $defaultItem;
switch ($action) {
case 's':
// Sell case
break;
case 'i':
// Inventory case
break;
case 'r':
// Refill case
break;
}
}

Loading…
Cancel
Save