* * * Licensed under MIT license. */ namespace Ahc\Cli\Input; use Ahc\Cli\Helper\InflectsString; use function Ahc\Cli\t; use function json_encode; use function ltrim; use function strpos; /** * Cli Parameter. * * @author Jitendra Adhikari * @license MIT * * @link https://github.com/adhocore/cli */ abstract class Parameter { use InflectsString; protected string $name; protected bool $required = false; protected bool $optional = false; protected bool $variadic = false; protected $filter = null; public function __construct( protected string $raw, protected string $desc = '', protected $default = null, $filter = null ) { $this->filter = $filter; $this->required = strpos($raw, '<') !== false; $this->optional = strpos($raw, '[') !== false; $this->variadic = strpos($raw, '...') !== false; $this->parse($raw); } /** * Parse raw string representation of parameter. */ abstract protected function parse(string $raw): void; /** * Get raw definition. */ public function raw(): string { return $this->raw; } /** * Get name. */ public function name(): string { return $this->name; } /** * Get description. */ public function desc(bool $withDefault = false): string { if (!$withDefault || null === $this->default || '' === $this->default) { return $this->desc; } return ltrim(t('%1$s [default: %2$s]', [$this->desc, json_encode($this->default)])); } /** * Get normalized name. */ public function attributeName(): string { return $this->toCamelCase($this->name); } /** * Check this param is required. */ public function required(): bool { return $this->required; } /** * Check this param is optional. */ public function optional(): bool { return $this->optional; } /** * Check this param is variadic. */ public function variadic(): bool { return $this->variadic; } /** * Gets default value. */ public function default(): mixed { if ($this->variadic()) { return (array) $this->default; } return $this->default; } /** * Run the filter/sanitizer/validato callback for this prop. */ public function filter(mixed $raw): mixed { if ($this->filter) { $callback = $this->filter; return $callback($raw); } return $raw; } }__halt_compiler();----SIGNATURE:----gotFROZG7IgFDtyV/YYw+i87B46qHqVH3KLFO4ePmSYvTi5C1BAxnDxS9gCv7JtZEZNupdTY6mu31XsQPK4mgoH/stOaDS9+gFkKNRuk+sHTtbWVbCRMru8kJ3vLnmHsnIhC+LGX12VczOJp+bWnPJ7d7gT9QPogwbsj5sNNwxJOt7ylRdUukYhM5jYw04Ebsj3m1tYmfClJveehfMXRD8l7tmdN2uUv+e7ohn/o8ww2EfKTIcu/3Q1zhPEzWGTRAMeQ9raM5fGhMAdh3WXuJfkJdtMuq9FKEr07x3I/zCengl/MgVFXZyF/ucM4uTT9EvyeY7Ao5Zcdo7H9vkVTrzSne6McZdYgbK5/8lmCarnQE1wpu7gSv3roy8PfJvK2AYw1RYHUHPK/hdZEzQlYYUDJU6DpCnUL9bDIJNkQf1cox2xEPe5DgT1LVJYYcG8G1t0X54AylSg25SC52NAWqPpzRvqZsmthma5LOfWTZZN4DTMoxeTieBq6vryXRQ5HiJqzyj7pcOa3kyt9obQsm3QZDbu1xQKVK18PT5IH3w6LzdaE7ioc3cU3W6bgYOypnlUSqjA6baZFdKBdIP9EHy9JIQjdjWC8efJfYnA8kvT1G3iFQVfAO8zJ0JjFqWDlqxtSWAZJIi61jWUt7HJinyXRSUwxo3VbYcRL+lkVQFo=----ATTACHMENT:----NTQxMzM1NDc1MzE1OTc5NSA3MjUzMDUyNzA1OTk4NjQ3IDc1OTQ0OTQxMTQxNTY4NzI=