fix minor issues
This commit is contained in:
parent
ae11ea6a56
commit
3f0ffc7f1d
6 changed files with 5195 additions and 24 deletions
|
|
@ -3,10 +3,10 @@
|
||||||
|
|
||||||
require __DIR__ . '/../autoload.php';
|
require __DIR__ . '/../autoload.php';
|
||||||
|
|
||||||
use Lvl0\AnagramFinder\TUI\Commands\FindAnagramWordsCommand;
|
use Lvl0\Countdown\TUI\Commands\FindAnagramWordsCommand;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
|
|
||||||
$application = new Application('Anagram Finder', '1.0.0');
|
$application = new Application('Anagram Finder', '1.0.0');
|
||||||
$application->addCommand(new FindAnagramWordsCommand());
|
$application->addCommand(new FindAnagramWordsCommand());
|
||||||
$application->setDefaultCommand('anagram:find-words');
|
$application->setDefaultCommand('countdown:letters');
|
||||||
$application->run();
|
$application->run();
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
require __DIR__ . '/../autoload.php';
|
require __DIR__ . '/../autoload.php';
|
||||||
|
|
||||||
use Lvl0\AnagramFinder\TUI\Commands\FindNumbersCommand;
|
use Lvl0\Countdown\TUI\Commands\FindNumbersCommand;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
|
|
||||||
$application = new Application('Countdown numbers Finder', '1.0.0');
|
$application = new Application('Countdown numbers Finder', '1.0.0');
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
"description": "A TUI anagram finder in PHP",
|
"description": "A TUI anagram finder in PHP",
|
||||||
"type": "project",
|
"type": "project",
|
||||||
"require": {
|
"require": {
|
||||||
"countdown/letters": "^0.1.2",
|
"countdown/letters": "^0.1.3",
|
||||||
"countdown/numbers": "^0.1.0",
|
"countdown/numbers": "^0.1.0",
|
||||||
"illuminate/collections": "^13.26",
|
"illuminate/collections": "^13.26",
|
||||||
"laravel/prompts": "^0.3.23"
|
"laravel/prompts": "^0.3.23"
|
||||||
|
|
@ -11,8 +11,8 @@
|
||||||
"license": "AGPL-3.0-only",
|
"license": "AGPL-3.0-only",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Lvl0\\AnagramFinder\\TUI\\": "src/",
|
"Lvl0\\Countdown\\TUI\\": "src/",
|
||||||
"Lvl0\\AnagramFinder\\TUI\\Tests\\": "tests/"
|
"Lvl0\\Countdown\\TUI\\Tests\\": "tests/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"authors": [
|
"authors": [
|
||||||
|
|
|
||||||
5153
composer.lock
generated
Normal file
5153
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,8 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Lvl0\AnagramFinder\TUI\Commands;
|
namespace Lvl0\Countdown\TUI\Commands;
|
||||||
|
|
||||||
use Lvl0\AnagramFinder\Core\Matcher;
|
use Lvl0\Countdown\Letters\Matcher;
|
||||||
use Symfony\Component\Console\Attribute\Argument;
|
use Symfony\Component\Console\Attribute\Argument;
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
use Symfony\Component\Console\Attribute\Option;
|
use Symfony\Component\Console\Attribute\Option;
|
||||||
|
|
@ -14,37 +14,38 @@ use function Laravel\Prompts\spin;
|
||||||
use function Laravel\Prompts\table;
|
use function Laravel\Prompts\table;
|
||||||
use function Laravel\Prompts\text;
|
use function Laravel\Prompts\text;
|
||||||
|
|
||||||
#[AsCommand(name: 'anagram:find-words')]
|
#[AsCommand(name: 'countdown:letters')]
|
||||||
class FindAnagramWordsCommand extends Command
|
class FindAnagramWordsCommand extends Command
|
||||||
{
|
{
|
||||||
public function __invoke(
|
public function __invoke(
|
||||||
#[Argument]
|
#[Argument]
|
||||||
?string $anagram,
|
?string $letters,
|
||||||
#[Argument]
|
#[Argument]
|
||||||
?int $minLength,
|
bool $all = false,
|
||||||
#[Option]
|
#[Option]
|
||||||
bool $top = false,
|
bool $single = false,
|
||||||
): int {
|
): int {
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
info("ANAGRAM FINDER");
|
info("ANAGRAM FINDER");
|
||||||
|
|
||||||
$anagram = $anagram ??= text("Enter the anagram", required: true);
|
$letters = $letters ??= text("Enter the letters", required: true);
|
||||||
$minLength = $top === true
|
|
||||||
? 3
|
|
||||||
: ($minLength ?: text(label: "Enter the minimum length of the results. (default=3)", placeholder: 3, default: 3, required: true));
|
|
||||||
|
|
||||||
info("Results for your anagram: " . $anagram);
|
info("Results for your letters: " . $letters);
|
||||||
|
|
||||||
$matches = spin(
|
$matches = spin(
|
||||||
callback: fn() => Matcher::findWords($anagram, $minLength),
|
callback: fn() => Matcher::findWords($letters),
|
||||||
message: 'Checking dictionary...',
|
message: 'Checking dictionary...',
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($top) {
|
if ($all) {
|
||||||
$matches = $matches->slice(0, 10);
|
$matches = $matches->slice(0, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($single) {
|
||||||
|
$matches = $matches->first();
|
||||||
|
}
|
||||||
|
|
||||||
table(
|
table(
|
||||||
headers: ["word", "length"],
|
headers: ["word", "length"],
|
||||||
rows: $matches->map(fn(string $word) => ['word' => $word, 'length' => strlen($word)])->toArray(),
|
rows: $matches->map(fn(string $word) => ['word' => $word, 'length' => strlen($word)])->toArray(),
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Lvl0\AnagramFinder\TUI\Commands;
|
namespace Lvl0\Countdown\TUI\Commands;
|
||||||
|
|
||||||
use Lvl0\AnagramFinder\TUI\Dtos\NumbersBag;
|
use Illuminate\Support\Collection;
|
||||||
use Lvl0\AnagramFinder\TUI\Dtos\Step;
|
use Lvl0\Countdown\Numbers\Dtos\NumbersBag;
|
||||||
use Lvl0\AnagramFinder\TUI\Services\NumbersService;
|
use Lvl0\Countdown\Numbers\Dtos\Step;
|
||||||
|
use Lvl0\Countdown\Numbers\Services\NumbersService;
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
|
||||||
use function Laravel\Prompts\callout;
|
use function Laravel\Prompts\callout;
|
||||||
use function Laravel\Prompts\clear;
|
use function Laravel\Prompts\clear;
|
||||||
|
use function Laravel\Prompts\error;
|
||||||
use function Laravel\Prompts\intro;
|
use function Laravel\Prompts\intro;
|
||||||
use function Laravel\Prompts\spin;
|
use function Laravel\Prompts\spin;
|
||||||
use function Laravel\Prompts\text;
|
use function Laravel\Prompts\text;
|
||||||
|
|
@ -23,9 +25,24 @@ class FindNumbersCommand extends Command
|
||||||
|
|
||||||
intro("NUMBERS FINDER");
|
intro("NUMBERS FINDER");
|
||||||
|
|
||||||
$numbers = NumbersBag::fromArray(explode(" ", text("Enter the numbers", required: true)));
|
$numbersInput = text("Enter the numbers", required: true);
|
||||||
|
|
||||||
|
$numbers = new NumbersBag(
|
||||||
|
new Collection(preg_split('/\s+/', trim($numbersInput), -1, PREG_SPLIT_NO_EMPTY))
|
||||||
|
->filter(fn (string $number) => ctype_digit($number))
|
||||||
|
->map(fn (string $number) => intval($number))
|
||||||
|
);
|
||||||
|
|
||||||
$target = text(label: "Enter the target number", required: true);
|
$target = text(label: "Enter the target number", required: true);
|
||||||
|
|
||||||
|
if (! ctype_digit($target)) {
|
||||||
|
error("Invalid target number");
|
||||||
|
|
||||||
|
return self::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$target = intval($target);
|
||||||
|
|
||||||
$result = spin(
|
$result = spin(
|
||||||
callback: fn() => new NumbersService($numbers)->solve($target),
|
callback: fn() => new NumbersService($numbers)->solve($target),
|
||||||
message: 'Calculating...',
|
message: 'Calculating...',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue