You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
phpcommandline/Tests/test.php

26 lines
1.1 KiB
PHP

<?php
require_once '../vendor/autoload.php';
use jrosset\CommandLine\Argument\Option\Flag;
use jrosset\CommandLine\Argument\Option\Value as OptionValue;
use jrosset\CommandLine\Argument\Parser\IntegerParser;
use jrosset\CommandLine\Argument\Parser\PathParser;
use jrosset\CommandLine\Argument\Value\Value;
use jrosset\CommandLine\CommandLine;
$cmdline = new CommandLine('Test', 'Programme de test', 'php test.php');
$cmdline->addDefaultArguments();
$cmdline->addOption(new Flag('array_form', false, 'Sous la forme d\'un tableau ?' . "\n" . 'Ou pas'));
$cmdline->addOption((new OptionValue('days', 'Nombre jour', new IntegerParser(0, 365)))->setDefault(3));
$cmdline->addOption((new OptionValue('years', 'Nombre d\'années', new IntegerParser(0)))->setDefault(5));
$cmdline->addValue((new Value('path', 'Chemin sauvegarde images', new PathParser(false), true)));
$cmdline->addExitCode(0, 'OK');
$cmdline->addExitCode(255, 'Unexpected error' . "\n" . 'Unknown error');
$args = $cmdline->parseNoExcept(255);
$cmdline->treatDefaultArguments($args, false);
echo "\n";
var_dump($args);