Use popt for printing --help message
authorJelmer Vernooij <jelmer@samba.org>
Thu, 29 Aug 2002 12:05:30 +0000 (12:05 +0000)
committerJelmer Vernooij <jelmer@samba.org>
Thu, 29 Aug 2002 12:05:30 +0000 (12:05 +0000)
source/rpcclient/rpcclient.c
source/torture/samtest.c
source/torture/vfstest.c

index 2d86fb1d3d0668ba90999cf8c76db0d65e6906d4..470ff7c1e326fae30c3cd14657b3c9434596f755 100644 (file)
@@ -578,7 +578,6 @@ static void usage(void)
 {
        printf("Usage: rpcclient [options] server\n");
 
-       printf("\t-A or --authfile authfile          File containing user credentials\n");
        printf("\t-c or --command \"command string\"   Execute semicolon separated cmds\n");
        printf("\t-d or --debug debuglevel           Set the debuglevel\n");
        printf("\t-l or --logfile logfile            Logfile to use instead of stdout\n");
@@ -622,20 +621,19 @@ static void usage(void)
           a fixed location or certain compilers complain */
        poptContext pc;
        struct poptOption long_options[] = {
-               {"authfile",    'A', POPT_ARG_STRING,   &opt_authfile, 'A'},
-               {"conf",        's', POPT_ARG_STRING,   &opt_configfile, 's'},
-               {"nopass",      'N', POPT_ARG_NONE,     &got_pass},
-               {"user",        'U', POPT_ARG_STRING,   &opt_username, 'U'},
-               {"workgroup",   'W', POPT_ARG_STRING,   &opt_domain, 'W'},
-               {"command",     'c', POPT_ARG_STRING,   &cmdstr},
-               {"logfile",     'l', POPT_ARG_STRING,   &opt_logfile, 'l'},
-               {"help",        'h', POPT_ARG_NONE,     0, 'h'},
-               {"dest-ip",     'I', POPT_ARG_STRING,   &opt_ipaddr, 'I'},
+               POPT_AUTOHELP
+               {"authfile",    'A', POPT_ARG_STRING,   &opt_authfile, 'A', "File containing user credentials"},
+               {"conf",        's', POPT_ARG_STRING,   &opt_configfile, 's', "Specify an alternative config file"},
+               {"nopass",      'N', POPT_ARG_NONE,     &got_pass, 'N', "Don't ask for a password"},
+               {"user",        'U', POPT_ARG_STRING,   &opt_username, 'U', "Set the network username"},
+               {"workgroup",   'W', POPT_ARG_STRING,   &opt_domain, 'W', "Set the domain name for user account"},
+               {"command",     'c', POPT_ARG_STRING,   &cmdstr, 'c', "Execute semicolon separated cmds"},
+               {"logfile",     'l', POPT_ARG_STRING,   &opt_logfile, 'l', "Logfile to use instead of stdout"},
+               {"dest-ip",     'I', POPT_ARG_STRING,   &opt_ipaddr, 'I', "Specify destination IP address"},
                { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
                { NULL }
        };
 
-
        setlinebuf(stdout);
 
        DEBUGLEVEL = 1;
index 15caf8820f4aeeb621bac39ca3a8cbcd66c4d9de..a6d1a288b21b645d2f0244c59aa753752cdb4edc 100644 (file)
@@ -43,8 +43,6 @@ static struct cmd_list {
        struct cmd_set *cmd_set;
 } *cmd_list;
 
-TALLOC_CTX *global_ctx;
-
 static char* next_command (char** cmdstr)
 {
        static pstring          command;
@@ -140,7 +138,7 @@ static NTSTATUS cmd_debuglevel(struct sam_context *sam, TALLOC_CTX *mem_ctx, int
 static NTSTATUS cmd_quit(struct sam_context *sam, TALLOC_CTX *mem_ctx, int argc, char **argv)
 {
        /* Cleanup */
-       talloc_destroy(global_ctx);
+       talloc_destroy(mem_ctx);
 
        exit(0);
        return NT_STATUS_OK; /* NOTREACHED */
@@ -229,16 +227,16 @@ static NTSTATUS do_cmd(struct sam_context *sam, struct cmd_set *cmd_entry, char
 
        if (cmd_entry->fn) {
 
-               if (global_ctx == NULL) {
+               if (mem_ctx == NULL) {
                        /* Create mem_ctx */
-                       if (!(global_ctx = talloc_init())) {
+                       if (!(mem_ctx = talloc_init())) {
                                DEBUG(0, ("talloc_init() failed\n"));
                                goto done;
                        }
                }
 
                /* Run command */
-               result = cmd_entry->fn(sam, global_ctx, argc, argv);
+               result = cmd_entry->fn(sam, mem_ctx, argc, argv);
 
        } else {
                fprintf (stderr, "Invalid command\n");
@@ -361,17 +359,13 @@ int main(int argc, char *argv[])
           a fixed location or certain compilers complain */
        poptContext pc;
        struct poptOption long_options[] = {
-/*             {"conf",        's', POPT_ARG_STRING,   &opt_configfile, 's'},*/
-               {"debug",       'd', POPT_ARG_INT,      &opt_debuglevel, 'd'},
-               {"debuglevel",  'd', POPT_ARG_INT,      &opt_debuglevel, 'd'},
-/*             {"user",        'U', POPT_ARG_STRING,   &opt_username, 'U'},*/
-               {"command",     'c', POPT_ARG_STRING,   &cmdstr},
-               {"logfile",     'l', POPT_ARG_STRING,   &opt_logfile, 'l'},
-               {"help",        'h', POPT_ARG_NONE,     0, 'h'},
+               POPT_AUTOHELP
+               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
+               {"command",     'c', POPT_ARG_STRING,   &cmdstr, 'c', "Execute semicolon seperated cmds"},
+               {"logfile",     'l', POPT_ARG_STRING,   &opt_logfile, 'l', "Logfile to use instead of stdout"},
                { 0, 0, 0, 0}
        };
 
-
        setlinebuf(stdout);
 
        DEBUGLEVEL = 1;
index 2186e28cdf290f5b5c49c14108a85ba50e0e47f4..824e8108bfd91f6d63d4a1ff0878dd3c47a26550 100644 (file)
@@ -470,19 +470,6 @@ BOOL reload_services(BOOL test)
        return (ret);
 }
 
-/* Print usage information */
-static void usage(void)
-{
-       printf("Usage: vfstest [options]\n");
-
-       printf("\t-c or --command \"command string\"   execute semicolon separated cmds\n");
-       printf("\t-f or --file filename  execute a set of operations as described in the file\n");
-       printf("\t-d or --debug debuglevel         set the debuglevel\n");
-       printf("\t-l or --logfile logfile           logfile to use instead of stdout\n");
-       printf("\t-h or --help                 Print this help message.\n");
-       printf("\n");
-}
-
 /* Main function */
 
 int main(int argc, char *argv[])
@@ -503,12 +490,11 @@ int main(int argc, char *argv[])
           a fixed location or certain compilers complain */
        poptContext pc;
        struct poptOption long_options[] = {
-               {"file",        'f', POPT_ARG_STRING,   &filename},
-               {"debug",       'd', POPT_ARG_INT,      &opt_debuglevel, 'd'},
-               {"debuglevel",  'd', POPT_ARG_INT,      &opt_debuglevel, 'd'},
-               {"command",     'c', POPT_ARG_STRING,   &cmdstr},
-               {"logfile",     'l', POPT_ARG_STRING,   &opt_logfile, 'l'},
-               {"help",        'h', POPT_ARG_NONE,     0, 'h'},
+               POPT_AUTOHELP
+               {"file",        'f', POPT_ARG_STRING,   &filename, 0, },
+               {"command",     'c', POPT_ARG_STRING,   &cmdstr, 0, "Execute specified list of commands" },
+               {"logfile",     'l', POPT_ARG_STRING,   &opt_logfile, 'l', 0, "Write output to specified logfile" },
+               { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
                { 0, 0, 0, 0}
        };
 
@@ -533,11 +519,6 @@ int main(int argc, char *argv[])
                case 'd':
                        DEBUGLEVEL = opt_debuglevel;
                        break;
-                       
-               case 'h':
-               default:
-                       usage();
-                       exit(1);
                }
        }