Beispiel #1
0
 /**
  * Prints the message of an occured error and exits the program.
  * This method is used to print an error message, as soon as an error
  * occurs end quit the program with return code -1. Optionally, the
  * method will trigger the help text to be printed after the error message.
  *
  * @param string $message The error message to print
  * @param bool $printHelp Whether to print the help after the error msg.
  */
 private function raiseError($message, $printHelp = false)
 {
     $this->output->outputLine($message, 'error');
     $this->output->outputLine();
     if ($printHelp === true) {
         $this->output->outputText($this->input->getHelpText(self::PROGRAM_DESCRIPTION), "help");
     }
     exit(-1);
 }
Beispiel #2
0
 /**
  * Prints the message of an occured error and exits the program.
  * This method is used to print an error message, as soon as an error
  * occurs end quit the program with return code -1. Optionally, the
  * method will trigger the help text to be printed after the error message.
  * 
  * @param string $message The error message to print
  * @param bool $printHelp Whether to print the help after the error msg.
  */
 private function raiseError($message, $printHelp = false)
 {
     $this->output->outputLine($message, 'error');
     $this->output->outputLine();
     if ($printHelp === true) {
         $this->output->outputText($this->input->getHelpText(ezcPersistentObjectSchemaGenerator::PROGRAM_DESCRIPTION), "help");
     }
     exit(-1);
 }
Beispiel #3
0
 /**
  * starts the command line interface for pFlow
  * @return void
  */
 public function run()
 {
     $this->setupInput();
     try {
         $this->input->process();
     } catch (\ezcConsoleOptionException $e) {
         die($e->getMessage() . "\nTry option -h to get a list of available options.\n");
     } catch (\ezcConsoleArgumentMandatoryViolationException $e) {
         die($e->getMessage() . "\nTry option -h to get a list of available options.\n");
     }
     if ($this->input->helpOptionSet()) {
         echo $this->input->getHelpText("\npFlow version " . self::VERSION . "\n\n" . "A tool for analysing control and data flow in PHP applications.");
     } else {
         // start generation
         $this->analyzer->setSources($this->input->getArguments(), $this->input->getOption('recursive')->value);
     }
 }
Beispiel #4
0
$input->argumentDefinition = new ezcConsoleArguments();
$input->argumentDefinition[0] = new ezcConsoleArgument("artist");
$input->argumentDefinition[0]->mandatory = true;
$input->argumentDefinition[0]->shorthelp = "The artist to search for";
$output = new ezcConsoleOutput();
$output->formats->info->color = 'blue';
$output->formats->error->color = 'red';
$output->formats->error->style = array('bold');
$output->formats->fatal->color = 'red';
$output->formats->fatal->style = array('bold', 'underlined');
$output->formats->fatal->bgcolor = 'black';
try {
    $input->process();
} catch (ezcConsoleArgumentMandatoryViolationException $e) {
    if ($helpOption->value === true) {
        $output->outputText($input->getHelpText("Auto-link by artist name"));
        exit;
    } else {
        $output->outputLine("No arguments given", "fatal");
        $output->outputText($input->getHelpText("Auto-link by artist name"));
        exit(1);
    }
} catch (ezcConsoleException $e) {
    die($e->getMessage());
}
if ($input->argumentDefinition["artist"]->value === null) {
    $output->outputLine("The <artist> argument is mandatory", 'fatal');
    $output->outputText($input->getHelpText("Auto-link by artist name"), 'fatal');
    exit;
}
var_dump($verboseOption->value);
$displayProgressOption->mandatory = false;
$displayProgressOption->shorthelp = "If progress output should be shown on the command-line.";
$params->registerOption($displayProgressOption);
// Add an argument for which extension to search
$params->argumentDefinition = new ezcConsoleArguments();
$params->argumentDefinition[0] = new ezcConsoleArgument('extension');
$params->argumentDefinition[0]->mandatory = false;
$params->argumentDefinition[0]->shorthelp = "Extension to generate autoload files for.";
$params->argumentDefinition[0]->default = getcwd();
// Process console parameters
try {
    $params->process();
} catch (ezcConsoleOptionException $e) {
    print $e->getMessage() . "\n";
    print "\n";
    echo $params->getHelpText('Autoload file generator.') . "\n";
    echo "\n";
    exit;
}
if ($helpOption->value === true) {
    echo $params->getHelpText('Autoload file generator.') . "\n";
    exit;
}
//}
if ($excludeDirsOption->value !== false) {
    $excludeDirs = explode(',', $excludeDirsOption->value);
} else {
    $excludeDirs = array();
}
$autoloadOptions = new ezpAutoloadGeneratorOptions();
$autoloadOptions->basePath = $params->argumentDefinition['extension']->value;
Beispiel #6
0
 public function testGetHelpTextBinarySafe()
 {
     $input = new ezcConsoleInput();
     $input->registerOption(new ezcConsoleOption('ö', 'öder', ezcConsoleInput::TYPE_NONE, null, false, 'ööö äää ööö äää', 'ööö äää ööö äää ööö äää ööö äää ööö äää ööö äää'));
     $res = "Usage: \$ {$_SERVER['argv'][0]} [-ö]  [[--] <args>]" . PHP_EOL . 'Test with UTF-8' . PHP_EOL . 'characters...' . PHP_EOL . '' . PHP_EOL . '-ö / --öder  ööö äää' . PHP_EOL . '             ööö äää' . PHP_EOL . '             ööö äää' . PHP_EOL . '             ööö äää' . PHP_EOL . '             ööö äää' . PHP_EOL . '             ööö äää' . PHP_EOL;
     $this->assertEquals($res, $input->getHelpText('Test with UTF-8 characters...', 20, true), 'Help text not generated correctly.');
 }
$option->isHelpOption = TRUE;
$option->arguments = FALSE;
$option = $input->registerOption(new ezcConsoleOption('d', 'dir', ezcConsoleInput::TYPE_STRING, '.', FALSE, 'Search Directory.', 'Directory to search for php class files, defaults to .'));
$option->arguments = FALSE;
$option = $input->registerOption(new ezcConsoleOption('t', 'target', ezcConsoleInput::TYPE_STRING, './autoload', FALSE, 'autoload dir', 'The directory where to save the autoload file, defaults to ./autoload'));
$option->arguments = FALSE;
$option = $input->registerOption(new ezcConsoleOption('p', 'prefix', ezcConsoleInput::TYPE_STRING, null, FALSE, 'classes prefix', 'The prefix of the classes for which the autoload file should be created'));
$option->arguments = FALSE;
$input->registerOption(new ezcConsoleOption('b', 'basedir', ezcConsoleInput::TYPE_STRING, '.', FALSE, 'basedir for autoload paths', 'Paths in the autoload array are written relatively to this dir.  Defaults to .'));
try {
    $input->process();
} catch (ezcConsoleOptionException $e) {
    die($e->getMessage() . "\n");
}
if ($input->getOption('h')->value === true) {
    echo $input->getHelpText('eZ components autoload generator');
    die;
}
foreach (array('dir', 'target', 'basedir') as $option) {
    ${$option} = realpath($input->getOption($option)->value);
    if (FALSE === ${$option}) {
        echo 'Given directory ' . $input->getOption($option)->value . ' for option ' . $option . " does not exist.\n";
        die;
    }
}
$prefix = $input->getOption('p')->value;
chdir($basedir);
$relPath = relPath($basedir, $dir);
$iterator = new DirectoryIteratorFilter($relPath);
foreach ($iterator as $file) {
    //    echo $file,"\n";
Beispiel #8
0
$helpOption->isHelpOption = true;
$helpOption->shorthelp = 'Display current help information.';
$extensionOption = $input->registerOption(new ezcConsoleOption('e', 'extension', ezcConsoleInput::TYPE_STRING));
$extensionOption->mandatory = true;
$extensionOption->shorthelp = 'Full path to the eZ Publish extension e.g \'/home/ls/public_html/ezp/extension/myextension\'';
$extensionNameOption = $input->registerOption(new ezcConsoleOption('n', 'extension-name', ezcConsoleInput::TYPE_STRING));
$extensionNameOption->mandatory = true;
$extensionNameOption->shorthelp = 'Extension name. e.g \'myextension\'';
try {
    $input->process();
} catch (ezcConsoleOptionException $e) {
    $output->outputLine($e->getMessage());
    exit;
}
if ($helpOption->value === true) {
    $output->outputText($input->getHelpText('This script generate an XML definition for eZ Publish extension package type.'));
    exit;
}
$sourceDir = $extensionOption->value;
$extensionName = $extensionNameOption->value;
$fileList = array();
recursiveList($sourceDir, '', $fileList);
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$packageRoot = $doc->createElement('extension');
$packageRoot->setAttribute('name', $extensionName);
foreach ($fileList as $file) {
    $fileNode = $doc->createElement('file');
    $fileNode->setAttribute('name', $file['name']);
    if ($file['path']) {
        $fileNode->setAttribute('path', $file['path']);
Beispiel #9
0
$helpOpt->shorthelp = 'Print help information.';
$helpOpt->longhelp = 'Display this help information about the program.';
$suiteOpt = $in->registerOption(new ezcConsoleOption('s', 'suite', ezcConsoleInput::TYPE_STRING, '*'));
$suiteOpt->shorthelp = 'Path pattern defining the client test suites to display data for.';
$suiteOpt->longhelp = 'This option may contain a path pattern as understood by glob(), defining the client test suites to display data for. An example would be "rfc" to only see the rfc tests or "r*" to see all suites starting with "r".';
$testOpt = $in->registerOption(new ezcConsoleOption('t', 'test', ezcConsoleInput::TYPE_STRING, '*'));
$testOpt->shorthelp = 'Path pattern defining the test cases to display data for.';
$testOpt->longhelp = 'This option may contain a path pattern as understood by glob(), defining the test cases to display data for. An example would be "get_*" to only see all test cases that start with "get_".';
$noColorOpt = $in->registerOption(new ezcConsoleOption('n', 'no-color'));
$noColorOpt->shorthelp = 'Switch of use of format codes (for logging).';
$noColorOpt->longhelp = 'Switches of the use of shell formatting codes, like color and style. This is particularly useful if you want to log the generated output.';
try {
    $in->process();
} catch (ezcConsoleException $e) {
    $out->outputLine($e->getMessage(), 'error');
    $out->outputLine($in->getHelpText('Webdav client test viewer'), 'error');
    exit(-1);
}
if ($helpOpt->value === true) {
    $out->outputLine($in->getHelpText('Webdav client test viewer', 80, true));
    exit(0);
}
if ($noColorOpt->value === true) {
    $out->options->useFormats = false;
}
$suites = glob(dirname(__FILE__) . "/../clients/{$suiteOpt->value}", GLOB_ONLYDIR);
foreach ($suites as $suite) {
    $tests = glob("{$suite}/{$testOpt->value}", GLOB_ONLYDIR);
    foreach ($tests as $test) {
        $requestInfos = loadFiles(glob("{$test}/request/*"));
        if (count($requestInfos) === 0) {
Beispiel #10
0
 /**
  * Displays the help text
  *
  * @param ezcConsoleInput $consoleInput
  */
 protected static function displayHelp($consoleInput)
 {
     echo $consoleInput->getHelpText('eZ Publish Test Runner');
 }
<?php

require_once 'tutorial_autoload.php';
$input = new ezcConsoleInput();
$helpOption = $input->registerOption(new ezcConsoleOption('h', 'help'));
$helpOption->isHelpOption = true;
$input->argumentDefinition = new ezcConsoleArguments();
$input->argumentDefinition[0] = new ezcConsoleArgument("source");
$input->argumentDefinition[0]->shorthelp = "The source directory.";
$input->argumentDefinition[1] = new ezcConsoleArgument("destination");
$input->argumentDefinition[1]->mandatory = false;
$input->argumentDefinition[1]->default = './';
$input->argumentDefinition[2] = new ezcConsoleArgument("iterations");
$input->argumentDefinition[2]->type = ezcConsoleInput::TYPE_INT;
$input->argumentDefinition[2]->shorthelp = "Number of iterations.";
$input->argumentDefinition[2]->longhelp = "The number of iterations to perform.";
try {
    $input->process();
} catch (ezcConsoleException $e) {
    die($e->getMessage());
}
if ($helpOption->value === true) {
    echo $input->getHelpText("A simple text program");
} else {
    echo "Source:      {$input->argumentDefinition["source"]->value}\n";
    echo "Destination: {$input->argumentDefinition["destination"]->value}\n";
    echo "Iterations:  " . ($input->argumentDefinition["iterations"]->value === null ? "not set" : $input->argumentDefinition["iterations"]->value);
}