]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - scripts/commandline.inc
move getUser() function to commandline.inc
[quix0rs-gnu-social.git] / scripts / commandline.inc
index a475e11d01abba19ba7fb9ba8126f00f312388c7..a29f588448db88f7d048be2d5475ebe9f786874e 100644 (file)
@@ -177,3 +177,27 @@ function get_option_value($opt, $alt=null)
 
     return null;
 }
+
+function getUser()
+{
+    $user = null;
+
+    if (have_option('i', 'id')) {
+        $id = get_option_value('i', 'id');
+        $user = User::staticGet('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);
+        if (empty($user)) {
+            throw new Exception("Can't find user with nickname '$nickname'");
+        }
+    } else {
+        show_help();
+        exit(1);
+    }
+
+    return $user;
+}