net: Add net_run_function3
authorKai Blin <kai@samba.org>
Thu, 22 May 2008 07:41:21 +0000 (09:41 +0200)
committerKai Blin <kai@samba.org>
Tue, 10 Jun 2008 07:45:19 +0000 (09:45 +0200)
(This used to be commit ba1108f06ae5860c8f418dc383b027068780abf9)

source3/utils/net.h
source3/utils/net_proto.h
source3/utils/net_util.c

index a5078d026644cec9ab8202a9ec5b80029762e83e..b816aec4e6b09e54e3310c5c01345aaac42e4773 100644 (file)
@@ -61,6 +61,7 @@ struct net_context {
        bool smb_encrypt;
        struct libnetapi_ctx *netapi_ctx;
 
+       bool display_usage;
        const char *share_type[];
 };
 
index 5af9d9e2cddc091c2d9cd31f705caf3b0454ff7c..31ee584c4c01b83d2fed08beef177f087c4c8452 100644 (file)
@@ -460,6 +460,8 @@ int net_run_function(struct net_context *c, int argc, const char **argv,
                                     int argc, const char **argv));
 int net_run_function2(struct net_context *c, int argc, const char **argv,
                      const char *whoami, struct functable2 *table);
+int net_run_function3(struct net_context *c, int argc, const char **argv,
+                     const char *whoami, struct functable3 *table);
 
 /* The following definitions come from utils/netlookup.c  */
 
index 20f004b790b02c527efeca16532fa5c71a456510..c641e61c5cbd44d605d700412f361bb4779b9960 100644 (file)
@@ -592,3 +592,30 @@ int net_run_function2(struct net_context *c, int argc, const char **argv,
        return -1;
 }
 
+int net_run_function3(struct net_context *c, int argc, const char **argv,
+                     const char *whoami, struct functable3 *table)
+{
+       int i;
+       if (argc != 0) {
+               for (i=0; table[i].funcname != NULL; i++) {
+                       if (StrCaseCmp(argv[0], table[i].funcname) == 0)
+                               return table[i].fn(c, argc-1, argv+1);
+               }
+       }
+
+       if (c->display_usage == false) {
+               d_fprintf(stderr, "Invalid command: %s %s\n", whoami,
+                         (argc > 0)?argv[0]:"");
+       }
+       d_printf("Usage:\n");
+       for (i=0; table[i].funcname != NULL; i++) {
+               if(c->display_usage == false)
+                       d_printf("%s %-15s %s\n", whoami, table[i].funcname,
+                                table[i].description);
+               else
+                       d_printf("%s\n", table[i].usage);
+       }
+
+       return c->display_usage?0:-1;
+}
+