Repository: trafficserver
Updated Branches:
  refs/heads/master 847d5c61a -> 7047a0c0c


TS-3157: standardize --help and --version arguments across apps


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/7047a0c0
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/7047a0c0
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/7047a0c0

Branch: refs/heads/master
Commit: 7047a0c0cb53e4ea8c88b7fd87d59560fcf7f036
Parents: 847d5c6
Author: James Peach <[email protected]>
Authored: Fri Oct 24 22:27:46 2014 -0700
Committer: James Peach <[email protected]>
Committed: Wed Oct 29 15:09:39 2014 -0700

----------------------------------------------------------------------
 CHANGES                              |  2 ++
 cmd/traffic_cop/traffic_cop.cc       | 12 ++-----
 cmd/traffic_layout/traffic_layout.cc | 13 ++------
 cmd/traffic_line/traffic_line.cc     | 48 +++++++++++----------------
 lib/ts/ink_args.cc                   | 55 ++++++++++++++++++++++---------
 lib/ts/ink_args.h                    |  6 +++-
 proxy/Main.cc                        | 15 ++-------
 proxy/logcat.cc                      | 37 ++++-----------------
 proxy/logstats.cc                    | 24 +++-----------
 proxy/sac.cc                         | 17 ++--------
 tools/jtest/jtest.cc                 | 48 +++++++--------------------
 11 files changed, 100 insertions(+), 177 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7047a0c0/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 99710a1..a1ff377 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 5.2.0
 
+  *) [TS-3157] Standardize --help and --version arguments across tools.
+
   *) [TS-3143] Create new Regex class that uses PCRE JIT.
 
   *) [TS-3115] Add server response time logging fields.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7047a0c0/cmd/traffic_cop/traffic_cop.cc
----------------------------------------------------------------------
diff --git a/cmd/traffic_cop/traffic_cop.cc b/cmd/traffic_cop/traffic_cop.cc
index d93a0a3..a195f56 100644
--- a/cmd/traffic_cop/traffic_cop.cc
+++ b/cmd/traffic_cop/traffic_cop.cc
@@ -80,7 +80,6 @@ static int coresig = 0;
 
 static int debug_flag = false;
 static int stdout_flag = false;
-static int version_flag = false;
 static int stop_flag = false;
 
 static char* admin_user;
@@ -1765,7 +1764,8 @@ static const ArgumentDescription argument_descriptions[] 
= {
   { "debug", 'd', "Enable debug logging", "F", &debug_flag, NULL, NULL },
   { "stdout", 'o', "Print log messages to standard output", "F", &stdout_flag, 
NULL, NULL },
   { "stop", 's', "Send child processes SIGSTOP instead of SIGKILL", "F", 
&stop_flag, NULL, NULL },
-  { "version", 'V', "Print Version String", "T", &version_flag, NULL, NULL},
+  HELP_ARGUMENT_DESCRIPTION(),
+  VERSION_ARGUMENT_DESCRIPTION()
 };
 
 int
@@ -1777,13 +1777,7 @@ main(int /* argc */, char *argv[])
   // Before accessing file system initialize Layout engine
   Layout::create();
 
-  process_args(argument_descriptions, countof(argument_descriptions), argv);
-
-  // Check for version number request
-  if (version_flag) {
-    fprintf(stderr, "%s\n", appVersionInfo.FullVersionInfoStr);
-    exit(0);
-  }
+  process_args(&appVersionInfo, argument_descriptions, 
countof(argument_descriptions), argv);
 
   if (stop_flag) {
     cop_log_trace("Cool! I think I'll be a STOP cop!");

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7047a0c0/cmd/traffic_layout/traffic_layout.cc
----------------------------------------------------------------------
diff --git a/cmd/traffic_layout/traffic_layout.cc 
b/cmd/traffic_layout/traffic_layout.cc
index 62df57c..d8b7875 100644
--- a/cmd/traffic_layout/traffic_layout.cc
+++ b/cmd/traffic_layout/traffic_layout.cc
@@ -28,10 +28,9 @@
 #include "I_RecProcess.h"
 #include "RecordsConfig.h"
 
-int VersionFlag;
-
 const ArgumentDescription argument_descriptions[] = {
-{"version", 'V', "Print version Id", "T", &VersionFlag, NULL, NULL},
+  HELP_ARGUMENT_DESCRIPTION(),
+  VERSION_ARGUMENT_DESCRIPTION()
 };
 
 static void
@@ -57,13 +56,7 @@ main(int /* argc ATS_UNUSED */, char **argv)
           __DATE__, __TIME__, BUILD_MACHINE, BUILD_PERSON, "");
 
   // Process command line arguments and dump into variables
-  process_args(argument_descriptions, countof(argument_descriptions), argv);
-
-  // check for the version number request
-  if (VersionFlag) {
-    ink_fputln(stderr, appVersionInfo.FullVersionInfoStr);
-    exit(0);
-  }
+  process_args(&appVersionInfo, argument_descriptions, 
countof(argument_descriptions), argv);
 
   Layout::create();
   RecProcessInit(RECM_STAND_ALONE, NULL /* diags */);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7047a0c0/cmd/traffic_line/traffic_line.cc
----------------------------------------------------------------------
diff --git a/cmd/traffic_line/traffic_line.cc b/cmd/traffic_line/traffic_line.cc
index e40ecf5..73ef29b 100644
--- a/cmd/traffic_line/traffic_line.cc
+++ b/cmd/traffic_line/traffic_line.cc
@@ -31,8 +31,6 @@
 #include <stdio.h>
 #include <string.h>
 
-static const char *programName;
-
 static char ReadVar[1024];
 static char MatchVar[1024];
 static char SetVar[1024];
@@ -54,7 +52,6 @@ static int ShowAlarms;
 static int ShowStatus;
 static int ShowBacktrace;
 static char ClearAlarms[1024];
-static int VersionFlag;
 static char viaHeader[1024];
 
 struct VIA
@@ -126,7 +123,7 @@ detailViaLookup(char flag)
     viaTable->viaData[(unsigned char) 'F'] = "connection open failed";
     break;
   default:
-    fprintf(stderr, "%s: %s: %c\n", programName, "Invalid VIA header 
character",flag);
+    fprintf(stderr, "%s: %s: %c\n", program_name, "Invalid VIA header 
character",flag);
     break;
   }
   return viaTable;
@@ -193,7 +190,7 @@ standardViaLookup(char flag)
       break;
     default:
       viaTable = new VIA();
-      fprintf(stderr, "%s: %s: %c\n", programName, "Invalid VIA header 
character",flag);
+      fprintf(stderr, "%s: %s: %c\n", program_name, "Invalid VIA header 
character",flag);
       break;
   }
   return viaTable;
@@ -297,7 +294,7 @@ handleArgInvocation()
     char *name = *ZeroNode ? ZeroNode : ZeroCluster;
 
     if ((err = TSRecordGet(name, rec_ele)) != TS_ERR_OKAY) {
-      fprintf(stderr, "%s: %s\n", programName, TSGetErrorMessage(err));
+      fprintf(stderr, "%s: %s\n", program_name, TSGetErrorMessage(err));
       TSRecordEleDestroy(rec_ele);
       return err;
     }
@@ -403,14 +400,14 @@ handleArgInvocation()
     return err;
   } else if (*ReadVar != '\0') {        // Handle a value read
     if (*SetVar != '\0' || *VarValue != '\0') {
-      fprintf(stderr, "%s: Invalid Argument Combination: Can not read and set 
values at the same time\n", programName);
+      fprintf(stderr, "%s: Invalid Argument Combination: Can not read and set 
values at the same time\n", program_name);
       return TS_ERR_FAIL;
     } else {
       TSMgmtError err;
       TSRecordEle *rec_ele = TSRecordEleCreate();
 
       if ((err = TSRecordGet(ReadVar, rec_ele)) != TS_ERR_OKAY) {
-        fprintf(stderr, "%s: %s\n", programName, TSGetErrorMessage(err));
+        fprintf(stderr, "%s: %s\n", program_name, TSGetErrorMessage(err));
       } else {
         switch (rec_ele->rec_type) {
         case TS_REC_INT:
@@ -426,7 +423,7 @@ handleArgInvocation()
           printf("%s\n", rec_ele->valueT.string_val);
           break;
         default:
-          fprintf(stderr, "%s: unknown record type (%d)\n", programName, 
rec_ele->rec_type);
+          fprintf(stderr, "%s: unknown record type (%d)\n", program_name, 
rec_ele->rec_type);
           err = TS_ERR_FAIL;
           break;
         }
@@ -436,7 +433,7 @@ handleArgInvocation()
     }
   } else if (*MatchVar != '\0') {        // Handle a value read
     if (*SetVar != '\0' || *VarValue != '\0') {
-      fprintf(stderr, "%s: Invalid Argument Combination: Can not read and set 
values at the same time\n", programName);
+      fprintf(stderr, "%s: Invalid Argument Combination: Can not read and set 
values at the same time\n", program_name);
       return TS_ERR_FAIL;
     } else {
       TSMgmtError err;
@@ -444,7 +441,7 @@ handleArgInvocation()
 
       if ((err = TSRecordGetMatchMlt(MatchVar, list)) != TS_ERR_OKAY) {
         char* msg = TSGetErrorMessage(err);
-        fprintf(stderr, "%s: %s\n", programName, msg);
+        fprintf(stderr, "%s: %s\n", program_name, msg);
         ats_free(msg);
       }
 
@@ -478,14 +475,14 @@ handleArgInvocation()
     }
   } else if (*SetVar != '\0') { // Setting a variable
     if (*VarValue == '\0') {
-      fprintf(stderr, "%s: Set requires a -v argument\n", programName);
+      fprintf(stderr, "%s: Set requires a -v argument\n", program_name);
       return TS_ERR_FAIL;
     } else {
       TSMgmtError err;
       TSActionNeedT action;
 
       if ((err = TSRecordSet(SetVar, VarValue, &action)) != TS_ERR_OKAY) {
-        fprintf(stderr, "%s: Please correct your variable name and|or 
value\n", programName);
+        fprintf(stderr, "%s: Please correct your variable name and|or 
value\n", program_name);
         return err;
       }
 
@@ -508,7 +505,7 @@ handleArgInvocation()
       return err;
     }
   } else if (*VarValue != '\0') {       // We have a value but no variable to 
set
-    fprintf(stderr, "%s: Must specify variable to set with -s when using 
-v\n", programName);
+    fprintf(stderr, "%s: Must specify variable to set with -s when using 
-v\n", program_name);
     return TS_ERR_FAIL;
   } else if (*viaHeader != '\0') {        // Read via header and decode
     TSMgmtError rc;
@@ -516,7 +513,7 @@ handleArgInvocation()
     return rc;
   }
 
-  fprintf(stderr, "%s: No arguments specified\n", programName);
+  fprintf(stderr, "%s: No arguments specified\n", program_name);
   return TS_ERR_FAIL;
 }
 
@@ -526,7 +523,10 @@ main(int /* argc ATS_UNUSED */, char **argv)
   AppVersionInfo appVersionInfo;
   TSMgmtError status;
 
-  programName = argv[0];
+  // build the application information structure
+  appVersionInfo.setup(PACKAGE_NAME, "traffic_line", PACKAGE_VERSION, 
__DATE__, __TIME__, BUILD_MACHINE, BUILD_PERSON, "");
+
+  program_name = appVersionInfo.AppStr;
 
   ReadVar[0] = '\0';
   MatchVar[0] = '\0';
@@ -544,16 +544,12 @@ main(int /* argc ATS_UNUSED */, char **argv)
   ClearNode = 0;
   ZeroCluster[0] = '\0';
   ZeroNode[0] = '\0';
-  VersionFlag = 0;
   *StorageCmdOffline = 0;
   ShowAlarms = 0;
   ShowStatus = 0;
   ClearAlarms[0] = '\0';
   viaHeader[0] = '\0';
 
-  // build the application information structure
-  appVersionInfo.setup(PACKAGE_NAME,"traffic_line", PACKAGE_VERSION, __DATE__, 
__TIME__, BUILD_MACHINE, BUILD_PERSON, "");
-
 /* Argument description table used to describe how to parse command line args, 
*/
 /* see 'ink_args.h' for meanings of the various fields */
   ArgumentDescription argument_descriptions[] = {
@@ -562,7 +558,6 @@ main(int /* argc ATS_UNUSED */, char **argv)
     {"match_var", 'm', "Match Variable", "S1024", &MatchVar, NULL, NULL},
     {"set_var", 's', "Set Variable (requires -v option)", "S1024", &SetVar, 
NULL, NULL},
     {"value", 'v', "Set Value (used with -s option)", "S1024", &VarValue, 
NULL, NULL},
-    {"help", 'h', "Help", NULL, NULL, NULL, usage},
     {"reread_config", 'x', "Reread Config Files", "F", &ReRead, NULL, NULL},
     {"restart_cluster", 'M', "Restart traffic_manager (cluster wide)", "F", 
&ShutdownMgmtCluster, NULL, NULL},
     {"restart_local", 'L', "Restart traffic_manager (local node)", "F", 
&ShutdownMgmtLocal, NULL, NULL},
@@ -579,18 +574,13 @@ main(int /* argc ATS_UNUSED */, char **argv)
     {"clear_alarms", '-', "Clear specified, or all,  alarms", "S1024", 
&ClearAlarms, NULL, NULL},
     {"status", '-', "Show proxy server status", "F", &ShowStatus, NULL, NULL},
     {"backtrace", '-', "Show proxy stack backtrace", "F", &ShowBacktrace, 
NULL, NULL},
-    {"version", 'V', "Print Version Id", "T", &VersionFlag, NULL, NULL},
     {"decode_via", '-', "Decode Via Header", "S1024", &viaHeader, NULL, NULL},
+    HELP_ARGUMENT_DESCRIPTION(),
+    VERSION_ARGUMENT_DESCRIPTION()
   };
 
   // Process command line arguments and dump into variables
-  process_args(argument_descriptions, countof(argument_descriptions), argv);
-
-  // check for the version number request
-  if (VersionFlag) {
-    ink_fputln(stderr, appVersionInfo.FullVersionInfoStr);
-    exit(0);
-  }
+  process_args(&appVersionInfo, argument_descriptions, 
countof(argument_descriptions), argv);
 
   // Connect to Local Manager and do it.
   if (TS_ERR_OKAY != TSInit(NULL, 
static_cast<TSInitOptionT>(TS_MGMT_OPT_NO_EVENTS | TS_MGMT_OPT_NO_SOCK_TESTS))) 
{

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7047a0c0/lib/ts/ink_args.cc
----------------------------------------------------------------------
diff --git a/lib/ts/ink_args.cc b/lib/ts/ink_args.cc
index 528ab16..97f5f1b 100644
--- a/lib/ts/ink_args.cc
+++ b/lib/ts/ink_args.cc
@@ -56,11 +56,23 @@ static const char *argument_types_descriptions[] = {
 // Functions
 //
 
+static bool
+arg_is_version_flag(const ArgumentDescription * arg)
+{
+  return strcmp(arg->name, "version") == 0 && arg->key == 'V';
+}
+
 static void
-process_arg(const ArgumentDescription * argument_descriptions,
+process_arg(const AppVersionInfo * appinfo, const ArgumentDescription * 
argument_descriptions,
             unsigned n_argument_descriptions, int i, char ***argv, const char 
*usage_string)
 {
   char *arg = NULL;
+
+  if (arg_is_version_flag(&argument_descriptions[i])) {
+    ink_fputln(stdout, appinfo->FullVersionInfoStr);
+    exit(0);
+  }
+
   if (argument_descriptions[i].type) {
     char type = argument_descriptions[i].type[0];
     if (type == 'F' || type == 'f')
@@ -136,7 +148,7 @@ show_argument_configuration(const ArgumentDescription * 
argument_descriptions, u
 }
 
 void
-process_args(const ArgumentDescription * argument_descriptions, unsigned 
n_argument_descriptions, char **argv, const char *usage_string)
+process_args(const AppVersionInfo * appinfo, const ArgumentDescription * 
argument_descriptions, unsigned n_argument_descriptions, char **argv, const 
char *usage_string)
 {
   unsigned i = 0;
   //
@@ -168,14 +180,14 @@ process_args(const ArgumentDescription * 
argument_descriptions, unsigned n_argum
   //
   // Grab Command Line Arguments
   //
-  program_name = argv[0];
+  program_name = appinfo->AppStr;
   while (*++argv) {
     if (**argv == '-') {
       if ((*argv)[1] == '-') {
         for (i = 0; i < n_argument_descriptions; i++)
           if (!strcmp(argument_descriptions[i].name, (*argv) + 2)) {
             *argv += strlen(*argv) - 1;
-            process_arg(argument_descriptions, n_argument_descriptions, i, 
&argv, usage_string);
+            process_arg(appinfo, argument_descriptions, 
n_argument_descriptions, i, &argv, usage_string);
             break;
           }
         if (i >= n_argument_descriptions)
@@ -184,11 +196,12 @@ process_args(const ArgumentDescription * 
argument_descriptions, unsigned n_argum
         while (*++(*argv))
           for (i = 0; i < n_argument_descriptions; i++)
             if (argument_descriptions[i].key == **argv) {
-              process_arg(argument_descriptions, n_argument_descriptions, i, 
&argv, usage_string);
+              process_arg(appinfo, argument_descriptions, 
n_argument_descriptions, i, &argv, usage_string);
               break;
             }
-        if (i >= n_argument_descriptions)
+        if (i >= n_argument_descriptions) {
           usage(argument_descriptions, n_argument_descriptions, usage_string);
+        }
       }
     } else {
       if (n_file_arguments >= countof(file_arguments)) {
@@ -234,17 +247,25 @@ usage(const ArgumentDescription * argument_descriptions, 
unsigned n_argument_des
     case 'L':
       fprintf(stderr, " %-9" PRId64 "", *(int64_t *) 
argument_descriptions[i].location);
       break;
-    case 'S':
-      if (*(char *) argument_descriptions[i].location) {
-        if (strlen((char *) argument_descriptions[i].location) < 10)
-          fprintf(stderr, " %-9s", (char *) argument_descriptions[i].location);
-        else {
-          ((char *) argument_descriptions[i].location)[7] = 0;
-          fprintf(stderr, " %-7s..", (char *) 
argument_descriptions[i].location);
+    case 'S': {
+      char * location;
+      if (argument_descriptions[i].type[1] == '*') {
+        location = *(char **)argument_descriptions[i].location;
+      } else {
+        location = (char *)argument_descriptions[i].location;
+      }
+
+      if (location) {
+        if (strlen(location) < 10) {
+          fprintf(stderr, " %-9s", location);
+        } else {
+          fprintf(stderr, " %-7.7s..", location);
         }
-      } else
+      } else {
         fprintf(stderr, " (null)   ");
+      }
       break;
+    }
     case 'D':
       fprintf(stderr, " %-9.3f", *(double *) 
argument_descriptions[i].location);
       break;
@@ -254,7 +275,11 @@ usage(const ArgumentDescription * argument_descriptions, 
unsigned n_argument_des
     case 'T':
     case 'f':
     case 'F':
-      fprintf(stderr, " %-9s", *(int *) argument_descriptions[i].location ? 
"true " : "false");
+      if (argument_descriptions[i].location) {
+        fprintf(stderr, " %-9s", *(int *) argument_descriptions[i].location ? 
"true " : "false");
+      } else {
+        fprintf(stderr, " %-9s", "false");
+      }
       break;
     }
     fprintf(stderr, " %s\n", argument_descriptions[i].description);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7047a0c0/lib/ts/ink_args.h
----------------------------------------------------------------------
diff --git a/lib/ts/ink_args.h b/lib/ts/ink_args.h
index 74d1081..d74ef5f 100644
--- a/lib/ts/ink_args.h
+++ b/lib/ts/ink_args.h
@@ -34,6 +34,7 @@ Process arguments
 #define MAX_FILE_ARGUMENTS 100
 
 struct ArgumentDescription;
+class AppVersionInfo;
 
 typedef void ArgumentFunction(const ArgumentDescription * 
argument_descriptions, unsigned n_argument_descriptions, const char *arg);
 
@@ -59,6 +60,9 @@ struct ArgumentDescription
   ArgumentFunction *pfn;
 };
 
+#define VERSION_ARGUMENT_DESCRIPTION() {"version", 'V', "Print version 
string", NULL, NULL, NULL, NULL}
+#define HELP_ARGUMENT_DESCRIPTION() {"help", 'h', "Print usage information", 
NULL, NULL, NULL, usage}
+
 /* Global Data
 */
 extern const char *file_arguments[];  // exported by process_args()
@@ -73,7 +77,7 @@ void usage(const ArgumentDescription * argument_descriptions, 
unsigned n_argumen
 
 /* Process all arguments
 */
-void process_args(const ArgumentDescription * argument_descriptions,
+void process_args(const AppVersionInfo * appinfo, const ArgumentDescription * 
argument_descriptions,
                   unsigned n_argument_descriptions, char **argv, const char 
*usage_string = 0);
 
 #endif /*_INK_ARGS_H*/

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7047a0c0/proxy/Main.cc
----------------------------------------------------------------------
diff --git a/proxy/Main.cc b/proxy/Main.cc
index 9bb465e..46f340d 100644
--- a/proxy/Main.cc
+++ b/proxy/Main.cc
@@ -102,7 +102,6 @@ extern "C" int plock(int);
 #define DEFAULT_COMMAND_FLAG              0
 
 #define DEFAULT_VERBOSE_FLAG              0
-#define DEFAULT_VERSION_FLAG              0
 #define DEFAULT_STACK_TRACE_FLAG          0
 
 #if DEFAULT_COMMAND_FLAG
@@ -120,8 +119,6 @@ static void * mgmt_restart_shutdown_callback(void *, char 
*, int data_len);
 static void*  mgmt_storage_device_cmd_callback(void* x, char* data, int len);
 static void init_ssl_ctx_callback(void *ctx, bool server);
 
-static int version_flag = DEFAULT_VERSION_FLAG;
-
 static int num_of_net_threads = ink_number_of_processors();
 static int num_of_udp_threads = 0;
 static int num_accept_threads  = 0;
@@ -174,7 +171,6 @@ static const ArgumentDescription argument_descriptions[] = {
    "PROXY_HTTP_ACCEPT_PORT", NULL},
   {"cluster_port", 'P', "Cluster Port Number", "I", &cluster_port_number, 
"PROXY_CLUSTER_PORT", NULL},
   {"dprintf_level", 'o', "Debug output level", "I", &cmd_line_dprintf_level, 
"PROXY_DPRINTF_LEVEL", NULL},
-  {"version", 'V', "Print Version String", "T", &version_flag, NULL, NULL},
 
 #if TS_HAS_TESTS
   {"regression", 'R',
@@ -210,7 +206,8 @@ static const ArgumentDescription argument_descriptions[] = {
 
   {"accept_mss", ' ', "MSS for client connections", "I", &accept_mss, NULL, 
NULL},
   {"poll_timeout", 't', "poll timeout in milliseconds", "I", &poll_timeout, 
NULL, NULL},
-  {"help", 'h', "HELP!", NULL, NULL, NULL, usage},
+  HELP_ARGUMENT_DESCRIPTION(),
+  VERSION_ARGUMENT_DESCRIPTION()
 };
 
 //
@@ -1243,13 +1240,7 @@ main(int /* argc ATS_UNUSED */, char **argv)
   Layout::create();
   chdir_root(); // change directory to the install root of traffic server.
 
-  process_args(argument_descriptions, countof(argument_descriptions), argv);
-
-  // Check for version number request
-  if (version_flag) {
-    fprintf(stderr, "%s\n", appVersionInfo.FullVersionInfoStr);
-    _exit(0);
-  }
+  process_args(&appVersionInfo, argument_descriptions, 
countof(argument_descriptions), argv);
 
   // Set stdout/stdin to be unbuffered
   setbuf(stdout, NULL);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7047a0c0/proxy/logcat.cc
----------------------------------------------------------------------
diff --git a/proxy/logcat.cc b/proxy/logcat.cc
index 4a9cc56..6c6b83e 100644
--- a/proxy/logcat.cc
+++ b/proxy/logcat.cc
@@ -46,8 +46,6 @@
 #include "Log.h"
 
 // logcat-specific command-line flags
-static int version_flag = 0;
-static int help = 0;
 static int squid_flag = 0;
 static int follow_flag = 0;
 static int clf_flag = 0;
@@ -61,29 +59,18 @@ int auto_clear_cache_flag = 0;
 static const ArgumentDescription argument_descriptions[] = {
 
   {"output_file", 'o', "Specify output file", "S1023", &output_file, NULL, 
NULL},
-  {"auto_filenames", 'a', "Automatically generate output names",
-   "T", &auto_filenames, NULL, NULL},
+  {"auto_filenames", 'a', "Automatically generate output names", "T", 
&auto_filenames, NULL, NULL},
   {"follow", 'f', "Follow the log file as it grows", "T", &follow_flag, NULL, 
NULL},
   {"clf", 'C', "Convert to Common Logging Format", "T", &clf_flag, NULL, NULL},
   {"elf", 'E', "Convert to Extended Logging Format", "T", &elf_flag, NULL, 
NULL},
-  {"help", 'h', "Give this help", "T", &help, NULL, NULL},
   {"squid", 'S', "Convert to Squid Logging Format", "T", &squid_flag, NULL, 
NULL},
   {"debug_tags", 'T', "Colon-Separated Debug Tags", "S1023", error_tags, NULL, 
NULL},
-  {"version", 'V', "Print Version Id", "T", &version_flag, NULL, NULL},
-  {"overwrite_output", 'w', "Overwrite existing output file(s)", "T",
-   &overwrite_existing_file, NULL, NULL},
-  {"elf2", '2', "Convert to Extended2 Logging Format", "T", &elf2_flag, NULL,
-   NULL}
+  {"overwrite_output", 'w', "Overwrite existing output file(s)", "T", 
&overwrite_existing_file, NULL, NULL},
+  {"elf2", '2', "Convert to Extended2 Logging Format", "T", &elf2_flag, NULL, 
NULL},
+  HELP_ARGUMENT_DESCRIPTION(),
+  VERSION_ARGUMENT_DESCRIPTION()
 };
 
-static const char *USAGE_LINE = "Usage: " PROGRAM_NAME " [-o output-file | -a] 
[-CEhS"
-#ifdef DEBUG
-  "T"
-#endif
-  "Vw2] [input-file ...]";
-
-
-
 static int
 process_file(int in_fd, int out_fd)
 {
@@ -238,20 +225,8 @@ main(int /* argc ATS_UNUSED */, char *argv[])
   // process command-line arguments
   //
   output_file[0] = 0;
-  process_args(argument_descriptions, countof(argument_descriptions), argv, 
USAGE_LINE);
+  process_args(&appVersionInfo, argument_descriptions, 
countof(argument_descriptions), argv);
 
-  // check for the version number request
-  //
-  if (version_flag) {
-    fprintf(stderr, "%s\n", appVersionInfo.FullVersionInfoStr);
-    _exit(NO_ERROR);
-  }
-  // check for help request
-  //
-  if (help) {
-    usage(argument_descriptions, countof(argument_descriptions), USAGE_LINE);
-    _exit(NO_ERROR);
-  }
   // check that only one of the -o and -a options was specified
   //
   if (output_file[0] != 0 && auto_filenames) {

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7047a0c0/proxy/logstats.cc
----------------------------------------------------------------------
diff --git a/proxy/logstats.cc b/proxy/logstats.cc
index 809b3b4..802edcc 100644
--- a/proxy/logstats.cc
+++ b/proxy/logstats.cc
@@ -637,12 +637,10 @@ struct CommandLineArgs
   int urls;                    // Produce JSON output of URL stats, arg is LRU 
size
   int show_urls;               // Max URLs to show
   int as_object;               // Show the URL stats as a single JSON object 
(not array)
-  int version;
-  int help;
 
   CommandLineArgs()
     : max_origins(0), min_hits(0), max_age(0), line_len(DEFAULT_LINE_LEN), 
incremental(0),
-      tail(0), summary(0), json(0), cgi(0), urls(0), show_urls(0), 
as_object(0), version(0), help(0)
+      tail(0), summary(0), json(0), cgi(0), urls(0), show_urls(0), as_object(0)
   {
     log_file[0] = '\0';
     origin_file[0] = '\0';
@@ -656,7 +654,6 @@ struct CommandLineArgs
 static CommandLineArgs cl;
 
 static ArgumentDescription argument_descriptions[] = {
-  {"help", 'h', "Give this help", "T", &cl.help, NULL, NULL},
   {"log_file", 'f', "Specific logfile to parse", "S1023", cl.log_file, NULL, 
NULL},
   {"origin_list", 'o', "Only show stats for listed Origins", "S4095", 
cl.origin_list, NULL, NULL},
   {"origin_file", 'O', "File listing Origins to show", "S1023", 
cl.origin_file, NULL, NULL},
@@ -674,7 +671,8 @@ static ArgumentDescription argument_descriptions[] = {
   {"max_age", 'a', "Max age for log entries to be considered", "I", 
&cl.max_age, NULL, NULL},
   {"line_len", 'l', "Output line length", "I", &cl.line_len, NULL, NULL},
   {"debug_tags", 'T', "Colon-Separated Debug Tags", "S1023", &error_tags, 
NULL, NULL},
-  {"version", 'V', "Print Version Id", "T", &cl.version, NULL, NULL},
+  HELP_ARGUMENT_DESCRIPTION(),
+  VERSION_ARGUMENT_DESCRIPTION()
 };
 
 static const char *USAGE_LINE =
@@ -684,7 +682,7 @@ void
 CommandLineArgs::parse_arguments(char** argv)
 {
   // process command-line arguments
-  process_args(argument_descriptions, countof(argument_descriptions), argv, 
USAGE_LINE);
+  process_args(&appVersionInfo, argument_descriptions, 
countof(argument_descriptions), argv, USAGE_LINE);
 
   // Process as "CGI" ?
   if (strstr(argv[0], ".cgi") || cgi) {
@@ -728,18 +726,6 @@ CommandLineArgs::parse_arguments(char** argv)
       }
     }
   }
-
-  // check for the version number request
-  if (version) {
-    std::cerr << appVersionInfo.FullVersionInfoStr << std::endl;
-    _exit(0);
-  }
-
-  // check for help request
-  if (help) {
-    usage(argument_descriptions, countof(argument_descriptions), USAGE_LINE);
-    _exit(0);
-  }
 }
 
 
@@ -2292,7 +2278,7 @@ main(int /* argc ATS_UNUSED */, char *argv[])
   struct flock lck;
 
   // build the application information structure
-  appVersionInfo.setup(PACKAGE_NAME,PROGRAM_NAME, PACKAGE_VERSION, __DATE__, 
__TIME__,
+  appVersionInfo.setup(PACKAGE_NAME, PROGRAM_NAME, PACKAGE_VERSION, __DATE__, 
__TIME__,
                        BUILD_MACHINE, BUILD_PERSON, "");
 
   // Before accessing file system initialize Layout engine

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7047a0c0/proxy/sac.cc
----------------------------------------------------------------------
diff --git a/proxy/sac.cc b/proxy/sac.cc
index df174c4..0d11c55 100644
--- a/proxy/sac.cc
+++ b/proxy/sac.cc
@@ -46,23 +46,19 @@
 
 #define DIAGS_LOG_FILENAME "collector.log"
 
-// sac-specific command-line flags
-//
-static int version_flag = 0;
-
 // command-line argument descriptions
 //
 
 ArgumentDescription argument_descriptions[] = {
 
-  {"version", 'V', "Print Version Id", "T", &version_flag, NULL, NULL},
 #ifdef DEBUG
   {"error_tags", 'T', "Colon-Separated Debug Tags", "S1023", &error_tags,
    NULL, NULL},
   {"action_tags", 'A', "Colon-Separated Debug Tags", "S1023", &action_tags,
    NULL, NULL},
 #endif
-  {"help", 'h', "HELP!", NULL, NULL, NULL, usage},
+  HELP_ARGUMENT_DESCRIPTION(),
+  VERSION_ARGUMENT_DESCRIPTION()
 };
 
 /*-------------------------------------------------------------------------
@@ -81,14 +77,7 @@ main(int /* argc ATS_UNUSED */, char *argv[])
   Layout::create();
   // take care of command-line arguments
   //
-  process_args(argument_descriptions, countof(argument_descriptions), argv);
-
-  // check for the version number request
-  //
-  if (version_flag) {
-    fprintf(stderr, "%s\n", appVersionInfo.FullVersionInfoStr);
-    _exit(0);
-  }
+  process_args(&appVersionInfo, argument_descriptions, 
countof(argument_descriptions), argv);
 
   diagsConfig = new DiagsConfig(DIAGS_LOG_FILENAME, error_tags, action_tags, 
false);
   diags = diagsConfig->diags;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7047a0c0/tools/jtest/jtest.cc
----------------------------------------------------------------------
diff --git a/tools/jtest/jtest.cc b/tools/jtest/jtest.cc
index 7ddacac..03ff69c 100644
--- a/tools/jtest/jtest.cc
+++ b/tools/jtest/jtest.cc
@@ -57,6 +57,7 @@
 #include "ParseRules.h"
 #include "ink_time.h"
 #include "ink_args.h"
+#include "I_Version.h"
 
 /*
  FTP - Traffic Server Template
@@ -86,16 +87,6 @@
 #define CLIENT_BUFSIZE             2048
 #define MAX_BUFSIZE                (65536 + 4096)
 
-//#define RETRY_CLIENT_WRITE_ERRORS
-#define VERSION_NUM "$Revision: 1.94 $"
-#if defined(BUILD_PERSON) && defined(BUILD_MACHINE)
-#define JTEST_VERSION ("JTest Version %s - " __DATE__ " " __TIME__ \
-                 " (" BUILD_PERSON "@" BUILD_MACHINE ")\n" )
-#else
-#define JTEST_VERSION ("JTest Version %s - " __DATE__ " " __TIME__ "\n")
-#endif
-// #define PRINT_LOCAL_PORT
-
 //
 // Contants
 //
@@ -109,6 +100,8 @@
 #define MAX_DEFERED_URLS      10000
 #define DEFERED_URLS_BLOCK    2000
 
+static AppVersionInfo appVersionInfo;
+
 static const char * hexdigits = "0123456789ABCDEFabcdef";
 static const char * dontunescapify = "#;/?+=&:@%";
 static const char * dontescapify = "#;/?+=&:@~.-_%";
@@ -122,9 +115,6 @@ enum FTP_MODE {
 typedef int (*accept_fn_t)(int);
 typedef int (*poll_cb)(int);
 
-static void jtest_usage(const ArgumentDescription * argument_descriptions,
-                        unsigned n_argument_descriptions, const char * arg);
-
 static int read_request(int sock);
 static int write_request(int sock);
 static int make_client (unsigned int addr, int port);
@@ -193,7 +183,6 @@ static int fullpage = 0;
 static int show_before = 0;
 static int show_headers = 0;
 static int server_keepalive = 4;
-static int version = 0;
 static int urls_mode = 0;
 static int pipeline = 1;
 static int hostrequest = 0;
@@ -315,7 +304,6 @@ static const ArgumentDescription argument_descriptions[] = {
    "JTEST_BANDWIDTH_TEST",NULL},
   {"drop_after_CL",'T',"Drop after Content-Length","F",
    &drop_after_CL, "JTEST_DROP",NULL},
-  {"version",'V',"Version","F",&version,"JTEST_VERSION",NULL},
   {"verbose",'v',"Verbose Flag","F",&verbose,"JTEST_VERBOSE",NULL},
   {"verbose_errors",'E',"Verbose Errors Flag","f",&verbose_errors,
    "JTEST_VERBOSE_ERRORS",NULL},
@@ -355,7 +343,8 @@ static const ArgumentDescription argument_descriptions[] = {
   {"evo_rate",'9',"Evolving Hotset Rate (evolutions/hour)","D",
    &evo_rate,"JTEST_EVOLVING_HOTSET_RATE",NULL},
   {"debug",'d',"Debug Flag","F",&debug,"JTEST_DEBUG",NULL},
-  {"help",'h',"Help",NULL,NULL,NULL,jtest_usage}
+  HELP_ARGUMENT_DESCRIPTION(),
+  VERSION_ARGUMENT_DESCRIPTION()
 };
 int n_argument_descriptions = countof(argument_descriptions);
 
@@ -538,21 +527,6 @@ static inline void append_string(char *dest, const char 
*src, int *offset_ptr,
 
 // End Library functions
 
-static void show_version() {
-  char b[] = VERSION_NUM;
-  char * v = strchr(b,':');
-  v += 2;
-  *strchr(v,'$') = 0;
-  printf(JTEST_VERSION, v);
-}
-
-static void jtest_usage(const ArgumentDescription * argument_descriptions,
-                 unsigned n_argument_descriptions, const char * arg)
-{
-  show_version();
-  usage(argument_descriptions, n_argument_descriptions, arg);
-}
-
 static void panic(const char * s) {
   fputs(s, stderr);
   exit(1);
@@ -2861,7 +2835,10 @@ static FILE * get_defered_urls(FILE * fp) {
   return fp;
 }
 
-int main(int argc __attribute__((unused)), char *argv[]) {
+int main(int argc __attribute__((unused)), char *argv[])
+{
+  appVersionInfo.setup(PACKAGE_NAME, "jtest", PACKAGE_VERSION, __DATE__, 
__TIME__, BUILD_MACHINE, BUILD_PERSON, "");
+
   /* for QA -- we want to be able to tail an output file
    * during execution "nohup jtest -P pxy -p prt &"
    */
@@ -2869,11 +2846,8 @@ int main(int argc __attribute__((unused)), char *argv[]) 
{
 
   fd = (FD*)malloc(MAXFDS * sizeof(FD));
   memset(fd,0,MAXFDS*sizeof(FD));
-  process_args(argument_descriptions, n_argument_descriptions, argv);
-  if (version) {
-    show_version();
-    exit(0);
-  }
+  process_args(&appVersionInfo, argument_descriptions, 
n_argument_descriptions, argv);
+
   if (!drand_seed)
     srand48((long)time(NULL));
   else

Reply via email to