Parcourir la source

[2713] Update manpage

Also replaced 'action' with 'command' (the first argument)
Jelte Jansen il y a 12 ans
Parent
commit
7f486337fa

+ 18 - 18
src/bin/usermgr/b10-cmdctl-usermgr.py.in

@@ -11,8 +11,8 @@
 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
 # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
-# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
-# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN COMMAND OF CONTRACT,
+# NEGLIGENCE OR OTHER TORTIOUS COMMAND, ARISING OUT OF OR IN CONNECTION
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 '''
@@ -36,8 +36,8 @@ DEFAULT_FILE = SYSCONFPATH + "/cmdctl-accounts.csv"
 
 # Actions that can be performed (used for argument parsing,
 # code paths, and output)
-ACTION_ADD = "add"
-ACTION_DELETE = "delete"
+COMMAND_ADD = "add"
+COMMAND_DELETE = "delete"
 
 # Non-zero return codes, used in tests
 BAD_ARGUMENTS = 1
@@ -124,18 +124,18 @@ class UserManager:
         self.user_info = new_user_info
         return True
 
-    def prompt_for_username(self, action):
+    def prompt_for_username(self, command):
         # Note, direct prints here are intentional
         while True :
-            name = input("Username to " + action + ": ")
+            name = input("Username to " + command + ": ")
             if name == "":
                 print("Error username can't be empty")
                 continue
 
-            if action == ACTION_ADD and self.username_exists(name):
+            if command == COMMAND_ADD and self.username_exists(name):
                  print("user already exists")
                  continue
-            elif action == ACTION_DELETE and not self.username_exists(name):
+            elif command == COMMAND_DELETE and not self.username_exists(name):
                  print("user does not exist")
                  continue
 
@@ -160,15 +160,15 @@ class UserManager:
         Returns False if there is a problem, True if everything seems OK.
         """
         if len(self.args) < 1:
-            self.print("Error: must specify an action")
+            self.print("Error: no command specified")
             return False
         if len(self.args) > 3:
             self.print("Error: extraneous arguments")
             return False
-        if self.args[0] not in [ ACTION_ADD, ACTION_DELETE ]:
-            self.print("Error: action must be either add or delete")
+        if self.args[0] not in [ COMMAND_ADD, COMMAND_DELETE ]:
+            self.print("Error: command must be either add or delete")
             return False
-        if self.args[0] == ACTION_DELETE and len(self.args) > 2:
+        if self.args[0] == COMMAND_DELETE and len(self.args) > 2:
             self.print("Error: delete only needs username, not a password")
             return False
         return True
@@ -181,14 +181,14 @@ class UserManager:
             self.print("Using accounts file: " + self.options.output_file)
             self.read_user_info()
 
-            action = self.args[0]
+            command = self.args[0]
 
             if len(self.args) > 1:
                 username = self.args[1]
             else:
-                username = self.prompt_for_username(action)
+                username = self.prompt_for_username(command)
 
-            if action == ACTION_ADD:
+            if command == COMMAND_ADD:
                 if len(self.args) > 2:
                     password = self.args[2]
                 else:
@@ -196,7 +196,7 @@ class UserManager:
                 if not self.add_user(username, password):
                     print("Error: username exists")
                     return USER_EXISTS
-            elif action == ACTION_DELETE:
+            elif command == COMMAND_DELETE:
                 if not self.delete_user(username):
                     print("Error: username does not exist")
                     return USER_DOES_NOT_EXIST
@@ -219,9 +219,9 @@ def set_options(parser):
                      )
 
 def main():
-    usage = "usage: %prog [options] <action> [username] [password]\n\n"\
+    usage = "usage: %prog [options] <command> [username] [password]\n\n"\
             "Arguments:\n"\
-            "  action\t\teither 'add' or 'delete'\n"\
+            "  command\t\teither 'add' or 'delete'\n"\
             "  username\t\tthe username to add or delete\n"\
             "  password\t\tthe password to set for the added user\n"\
             "\n"\

+ 25 - 16
src/bin/usermgr/b10-cmdctl-usermgr.xml

@@ -12,8 +12,8 @@
  - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  - AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN COMMAND OF CONTRACT, NEGLIGENCE
+ - OR OTHER TORTIOUS COMMAND, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  - PERFORMANCE OF THIS SOFTWARE.
 -->
 
@@ -47,10 +47,12 @@
 
       <arg><option>-f <replaceable>filename</replaceable></option></arg>
       <arg><option>-h</option></arg>
-      <arg><option>-v</option></arg>
-      <arg><option>--file <replaceable>filename</replaceable></option></arg>
+      <arg><option>--file=<replaceable>filename</replaceable></option></arg>
       <arg><option>--help</option></arg>
       <arg><option>--version</option></arg>
+      <arg choice="plain"><replaceable>command</replaceable></arg>
+      <arg><option>username</option></arg>
+      <arg><option>password</option></arg>
 
     </cmdsynopsis>
   </refsynopsisdiv>
@@ -58,24 +60,22 @@
   <refsect1>
     <title>DESCRIPTION</title>
     <para>The <command>b10-cmdctl-usermgr</command> tool may be used
-      to add accounts with passwords for the
+      to add and remove accounts with passwords for the
       <citerefentry><refentrytitle>b10-cmdctl</refentrytitle><manvolnum>8</manvolnum></citerefentry>
       daemon.
     </para>
 
     <para>
       By default, the accounts are saved in the
-      <filename>cmdctl-accounts.csv</filename> file in the current directory,
-      unless the <option>--filename</option> switch is used.
-      The entry is appended to the file.
-<!-- TODO: default should have full path? -->
+      <filename>cmdctl-accounts.csv</filename> file in the system config
+      directory, unless the <option>--filename</option> switch is used.
+      The entry is appended to or removed from the file.
     </para>
 
     <para>
-      The tool can't remove or replace existing entries.
+      The tool can't replace existing entries, but this can easily be
+      accomplished by removing the entry and adding a new one.
     </para>
-<!-- TODO: the tool can't remove or replace existing entries -->
-
   </refsect1>
 
   <refsect1>
@@ -83,6 +83,16 @@
 
     <para>The arguments are as follows:</para>
 
+    <para>
+      command is either 'add' or 'delete', respectively to add or delete users.
+    </para>
+
+    <para>
+      If a username and password are given (or just a username in case of
+      deletion), these are used. Otherwise, the tool shall prompt for a
+      username and/or password.
+    </para>
+
     <variablelist>
 
       <varlistentry>
@@ -97,14 +107,13 @@
         <term><option>-f <replaceable>filename</replaceable></option></term>
         <term><option>--file <replaceable>filename</replaceable></option></term>
         <listitem><para>
-          Define the filename to append the account to. The default
-          is <filename>cmdctl-accounts.csv</filename> in the current directory.
-<!-- TODO: default should have full path? -->
+          Define the filename to append the account to. The default is
+          <filename>cmdctl-accounts.csv</filename> in the system config
+          directory.
         </para></listitem>
       </varlistentry>
 
       <varlistentry>
-        <term><option>-v</option></term>
         <term><option>--version</option></term>
         <listitem><para>
           Report the version and exit.

+ 6 - 6
src/bin/usermgr/tests/b10-cmdctl-usermgr_test.py

@@ -9,8 +9,8 @@
 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
 # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
-# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
-# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN COMMAND OF CONTRACT,
+# NEGLIGENCE OR OTHER TORTIOUS COMMAND, ARISING OUT OF OR IN CONNECTION
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 import csv
@@ -91,10 +91,10 @@ class TestUserMgr(unittest.TestCase):
 
     def test_help(self):
         self.run_check(0,
-'''Usage: b10-cmdctl-usermgr [options] <action> [username] [password]
+'''Usage: b10-cmdctl-usermgr [options] <command> [username] [password]
 
 Arguments:
-  action		either 'add' or 'delete'
+  command		either 'add' or 'delete'
   username		the username to add or delete
   password		the password to set for the added user
 
@@ -205,11 +205,11 @@ Options:
         Assorted tests with bad command-line arguments
         """
         self.run_check(1,
-                       'Error: must specify an action\n',
+                       'Error: no command specified\n',
                        '',
                        [ self.TOOL ])
         self.run_check(1,
-                       'Error: action must be either add or delete\n',
+                       'Error: command must be either add or delete\n',
                        '',
                        [ self.TOOL, 'foo' ])
         self.run_check(1,