tui/src/ArgHandler.php

34 lines
667 B
PHP
Raw Normal View History

2026-08-22 17:52:17 +02:00
<?php
namespace Myrmidex\AnagramFinder;
use Illuminate\Support\Collection;
class ArgHandler
{
private Collection $args;
public function __construct(array $argv)
{
$this->args = new Collection($argv);
}
public static function make(array $argv): self
{
return new self($argv);
}
public function get(int $index)
{
return $this->args
->reject(fn ($word) => substr($word, 0, 2) === '--')
->get($index);
}
public function hasOption(string $option) {
return $this->args
->filter(fn ($word) => $word === '--' . $option)
->isNotEmpty();
}
}