php-vn-lib/lib/cli-app.php

40 lines
625 B
PHP

<?php
namespace Vn\Lib;
/**
* Implements command line applications.
*/
class CliApp extends App {
function run() {
$this->init();
if ($lang = substr(getenv('LANG'), 0, 2))
Locale::set($lang);
try {
$options = getopt('m:');
if (empty($options['m']))
$this->usage();
$db = $this->getSysConn();
echo "Executing method '{$options['m']}'\n";
$method = $this->loadMethod($options['m']);
$method->run($db);
}
catch (Exception $e) {
echo $e->getMessage()."\n";
exit(2);
}
}
function usage() {
global $argv;
echo "Usage: {$argv[0]} -m method_path\n";
exit(1);
}
}