Index: trunk/bin/user.cli.php
===================================================================
--- trunk/bin/user.cli.php	(revision 771)
+++ trunk/bin/user.cli.php	(revision 779)
@@ -89,8 +89,9 @@
 case 'list':
     $users = User_CLI::getList();
-    $positions = "%-3s  %-15s  %-11s  %-15s\n";
+    $positions = "%-3s  %-15s  %-30s  %-11s  %-15s\n";
     printf($positions,
         'ID',
         'USERNAME',
+        'EMAIL',
         'LAST_ACCESS',
         'LAST_IP'
@@ -100,4 +101,5 @@
             $u[$auth->getParam('db_primary_key')],
             $u['username'],
+            $u['email'],
             date($app->getParam('date_format'), strtotime($u['last_access_datetime'])),
             $u['last_login_ip']
@@ -108,23 +110,24 @@
 case 'create':
     $username = User_CLI::getArg(2, 'username');
-    $password = User_CLI::getArg(3, 'password');
+    $password = User_CLI::getArg(3, 'password', $auth->generatePassword());
+    $email = User_CLI::getArg(4, 'email', '');
     $user_id = $auth->getUserID($username);
     if (false !== $auth->getUserID($username)) {
-        printf("User '%s' already exists. Use 'update' instead.\n", $username);
+        printf("User `%s` already exists. Use `update` instead.\n", $username);
         exit(1);
     }
-    $user_id = User_CLI::create($username, $password);
-    printf("Created user '%s' (user_id %s).\n", $username, $user_id);
+    $user_id = User_CLI::create($username, $password, $email);
+    printf("Created user `%s` with password `%s` (user_id %s).\n", $username, $password, $user_id);
     break;
 
 case 'update':
     $username = User_CLI::getArg(2, 'username');
-    $password = User_CLI::getArg(3, 'password');
+    $password = User_CLI::getArg(3, 'password', $auth->generatePassword());
     if (!$user_id = $auth->getUserID($username)) {
-        printf("User '%s' not found. Use 'create' first.\n", $username);
+        printf("User `%s` not found. Use `create` first.\n", $username);
         exit(1);
     }
     $auth->setPassword($user_id, $password);
-    printf("Updated user '%s' password (user_id %s).\n", $username, $user_id);
+    printf("Updated user `%s` with password `%s` (user_id %s).\n", $username, $password, $user_id);
     break;
 
@@ -132,9 +135,9 @@
     $username = User_CLI::getArg(2, 'username');
     if (!$user_id = $auth->getUserID($username)) {
-        printf("User '%s' not found.\n", $username);
+        printf("User `%s` not found.\n", $username);
         exit(1);
     }
     User_CLI::remove($username);
-    printf("Removed user '%s' (user_id %s).\n", $username, $user_id);
+    printf("Removed user `%s` (user_id %s).\n", $username, $user_id);
     break;
 
@@ -157,16 +160,19 @@
 class User_CLI
 {
-    static public function getArg($pos, $name)
-    {
-        if (!isset($_SERVER['argv'][$pos]) || $_SERVER['argv'][$pos] == '') {
-            // Required arguments missing.
+    public static function getArg($pos, $name, $default=null)
+    {
+        if (isset($_SERVER['argv'][$pos]) && $_SERVER['argv'][$pos] != '') {
+            return $_SERVER['argv'][$pos];
+        }
+
+        if (null === $default) {
             printf("Required argument %s is missing. Lost? Try `%s help`.\n", strtoupper($name), basename($_SERVER['argv'][0]));
             exit(1);
         }
 
-        return $_SERVER['argv'][$pos];
-    }
-
-    static public function getList()
+        return $default;
+    }
+
+    public static function getList()
     {
         global $auth, $db;
@@ -185,5 +191,5 @@
     }
 
-    static public function create($username, $password)
+    public static function create($username, $password, $email)
     {
         global $auth, $db;
@@ -199,4 +205,8 @@
             $addtl_cols[] = ", account_id";
             $addtl_vals[] = ", '1'";
+        }
+        if (in_array('email', $cols) && '' != $email) {
+            $addtl_cols[] = ", email";
+            $addtl_vals[] = sprintf(", '%s'", $db->escapeString($email));
         }
         $db->query("
@@ -215,5 +225,5 @@
     }
 
-    static public function remove($username)
+    public static function remove($username)
     {
         global $auth, $db;
@@ -225,5 +235,5 @@
     }
 
-    static public function usage()
+    public static function usage()
     {
         ?>
@@ -234,8 +244,10 @@
 COMMANDS
 
-    help                        Display this help
-    list                        List all users.
-    create USERNAME PASSWORD    Create a user USERNAME authenticated by PASSWORD.
-    update USERNAME PASSWORD    Update the password for user USERNAME to PASSWORD.
+    help                                Display this help
+    list                                List all users.
+    create USERNAME [PASSWORD] [EMAIL]  Create a user USERNAME authenticated by PASSWORD.
+    update USERNAME [PASSWORD]          Update the password for user USERNAME to PASSWORD.
+
+If PASSWORD is not given, a random password will be generated and printed to the screen.
 
 This script must be run in a common site directory configured with a DB auth file,
