X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=scripts%2Fcommandline.inc;h=d7ee1588017bbf9c35a2ace7ca2cc4f9483d6a77;hb=b9a8b2ad056b0e944bdcae2b2a6ecb8f88a46f2f;hp=a29f588448db88f7d048be2d5475ebe9f786874e;hpb=dffec9f223c1e45832d274c34f7bd6624cbf87ea;p=quix0rs-gnu-social.git diff --git a/scripts/commandline.inc b/scripts/commandline.inc index a29f588448..d7ee158801 100644 --- a/scripts/commandline.inc +++ b/scripts/commandline.inc @@ -26,8 +26,8 @@ if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { exit(); } -define('STATUSNET', true); -define('LACONICA', true); // compatibility +define('GNUSOCIAL', true); +define('STATUSNET', true); //compatibility // Set various flags so we don't time out on long-running processes @@ -178,26 +178,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); +}