X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=scripts%2Fcommandline.inc;h=392166a98088dae0ca2f563b0a1709b68ccc7e9b;hb=d1afc7812413493a4b4d0d788c87150bad35b74d;hp=a29f588448db88f7d048be2d5475ebe9f786874e;hpb=f0105893b0b78ff88d08cc2417773ad8a44dc2fa;p=quix0rs-gnu-social.git diff --git a/scripts/commandline.inc b/scripts/commandline.inc index a29f588448..392166a980 100644 --- a/scripts/commandline.inc +++ b/scripts/commandline.inc @@ -26,8 +26,10 @@ if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { exit(); } -define('STATUSNET', true); -define('LACONICA', true); // compatibility +define('GNUSOCIAL', true); +define('STATUSNET', true); //compatibility + +define('GNUSOCIAL_CLI', true); // to know we're in a CLI environment // Set various flags so we don't time out on long-running processes @@ -35,6 +37,7 @@ ini_set("max_execution_time", "0"); ini_set("max_input_time", "0"); set_time_limit(0); mb_internal_encoding('UTF-8'); +error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED); // Add extlib to our path so we can get Console_Getopt @@ -178,26 +181,69 @@ function get_option_value($opt, $alt=null) return null; } +class NoUserArgumentException extends Exception +{ +} + function getUser() { $user = null; if (have_option('i', 'id')) { $id = get_option_value('i', 'id'); - $user = User::staticGet('id', $id); + $user = User::getKV('id', $id); if (empty($user)) { throw new Exception("Can't find user with id '$id'."); } } else if (have_option('n', 'nickname')) { $nickname = get_option_value('n', 'nickname'); - $user = User::staticGet('nickname', $nickname); + $user = User::getKV('nickname', $nickname); if (empty($user)) { throw new Exception("Can't find user with nickname '$nickname'"); } } else { - show_help(); - exit(1); + throw new NoUserArgumentException("No user argument specified."); } return $user; } + +/** "Printf not quiet" */ + +function printfnq() +{ + if (have_option('q', 'quiet')) { + return null; + } + + $cargs = func_num_args(); + + if ($cargs == 0) { + return 0; + } + + $args = func_get_args(); + $format = array_shift($args); + + return vprintf($format, $args); +} + +/** "Print when verbose" */ + +function printfv() +{ + if (!have_option('v', 'verbose')) { + return null; + } + + $cargs = func_num_args(); + + if ($cargs == 0) { + return 0; + } + + $args = func_get_args(); + $format = array_shift($args); + + return vprintf($format, $args); +}