Ejemplo n.º 1
0
#!/usr/bin/env php
<?php 
# to run these examples - make sure to do this first:
# composer install -d ../
// autoload
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
    require __DIR__ . '/../vendor/autoload.php';
} else {
    echo "To run this example, do this first:\ncomposer install -d ../\n";
    exit(1);
}
// specify the spec as human readable text
$cliopts = CLIOpts\CLIOpts::createFromTextSpec("\n<in_filename>\n-i, --id <id> specify an id (required)\n-o, --out <out_filename> output filename\n-v be verbose\n-h, --help show this help\n");
// get the values
$values = $cliopts->getOptsValues();
// check for the help switch before checking for valid values
if (isset($values['help'])) {
    $cliopts->showHelpTextAndExit();
}
// check validation.  Then generate help and exit if not valid.
$validator = $values->getValidator();
if (!$validator->isValid()) {
    $indent_text = '  ';
    print CLIOpts\Help\ConsoleFormat::applyformatToText('bold', 'white', 'red_bg', 'The following errors were found:') . "\n" . CLIOpts\Help\ConsoleFormat::applyformatToText('red', 'bold', $indent_text . implode("\n" . $indent_text, $validator->getErrors())) . "\n\n";
    $cliopts->showHelpTextAndExit();
    // *** script exited *** //
}
// show the values
echo "The values you supplied are:\n";
print_r((array) $values);
Ejemplo n.º 2
0
#!/usr/bin/env php
<?php 
# to run these examples - make sure to do this first:
# composer install -d ../
// autoload
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
    require __DIR__ . '/../vendor/autoload.php';
} else {
    echo "To run this example, do this first:\ncomposer install -d ../\n";
    exit(1);
}
// specify the spec as human readable text and run validation and help:
$values = CLIOpts\CLIOpts::run("\n  Usage: <in_filename>\n  -i, --id <id> specify an id (required)\n  -o, --out <out_filename> output filename\n  -v be verbose\n  -h, --help show this help\n");
// show the values
echo "The values you supplied are:\n";
print_r((array) $values);