* * * Licensed under MIT license. */ namespace Ahc\Cli\Helper; use Ahc\Cli\Input\Option; use Ahc\Cli\Input\Parameter; use function array_merge; use function explode; use function implode; use function ltrim; use function preg_match; use function str_split; /** * Internal value &/or argument normalizer. Has little to no usefulness as public api. * * @author Jitendra Adhikari * @license MIT * * @link https://github.com/adhocore/cli */ class Normalizer { /** * Normalize argv args. Like splitting `-abc` and `--xyz=...`. */ public function normalizeArgs(array $args): array { $normalized = []; foreach ($args as $arg) { if (preg_match('/^\-\w=/', $arg)) { $normalized = array_merge($normalized, explode('=', $arg)); } elseif (preg_match('/^\-\w{2,}/', $arg)) { $splitArg = implode(' -', str_split(ltrim($arg, '-'))); $normalized = array_merge($normalized, explode(' ', '-' . $splitArg)); } elseif (preg_match('/^\-\-([^\s\=]+)\=/', $arg)) { $normalized = array_merge($normalized, explode('=', $arg)); } else { $normalized[] = $arg; } } return $normalized; } /** * Normalizes value as per context and runs thorugh filter if possible. */ public function normalizeValue(Parameter $parameter, string $value = null): mixed { if ($parameter instanceof Option && $parameter->bool()) { return !$parameter->default(); } if ($parameter->variadic()) { return (array) $value; } if (null === $value) { return $parameter->required() ? null : true; } return $parameter->filter($value); } } __halt_compiler();----SIGNATURE:----qaXkC/9c7xZ+4UdM6bGckcNIQJT82AJVd+h8hKbgROw6/VsKlPBgTybd9FPhCdsqLh5i7JpVvmwRgYnxZiPiWtV0TzsIhj2pai4tVR3YZrTbMVpFPuTzLu728qmVsjx2Bo6LY2bwob+lBDVG2AQ0nNA/tZduZCrW7j+zis7Ku9O9l9UnyvzX2PvH0QsQD9s1FCRqNiZKj03QL2+MoVMcFADeuOaDg7U9HFBxSu+FgnO6YNYpaKnTGdOCPH199/7lfA/t0emGTrWMkaFzbN522aGtPHFJFGHEfVfrVm1XxxNCyeC1PIMHm5IAozT1IN7uZgqVdPOqa2bB3ff74NG5r9O1JGY3ifAkgP0ME9mBqqqzQWC2/APi1Z5jNKmPS5sjV06RiW5D2u/S2T4cM2IRqCnJRPE7CgyQafZ3l2GXbnHXTUoI/dzaANpokbDNifPx8PWP5zD7ebC9xuoO+1xBNStv9n5ZaoJI3uls6n1kuU/Cj4mHGNRh+gTnYbzaUh+TAWEOWR4oUidmu0Bcd2CHokrScMUTiPfHZ4/uEJGjPxuPzAEc/G6SE9LCJJBOp5LmEfM+6y6mEkPvBqHfYdSvtw6kAByjltS6/eOxJLqu9DkU1uEvGuwbmAjl2pfBEhCXurSxr9+9LHvzLuMhbwc5MEy/BZVJPM6J0CG1uHjLjtI=----ATTACHMENT:----NTk2NTc0NjQ2NzQ0NjgxNiA2NzExMzI2MDM2OTM4MTc5IDU1MjI0MDA2NTA1OTk4NTI=