You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2015/02/23 21:55:12 UTC

trafficserver git commit: TS-3403: stop parsing command-line options at the first non-option

Repository: trafficserver
Updated Branches:
  refs/heads/master ac4a7dbe2 -> 1d6f7d156


TS-3403: stop parsing command-line options at the first non-option

ink_args was skipping over file arguments to parse subsequent option
flags. While this allows options and file arguments to intermingle,
it makes it impossible to pass unparsed options down to subcommands.

To solve this, we stop parsing the command line at the first
non-option and declare that the rest of the options are file arguments.


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

Branch: refs/heads/master
Commit: 1d6f7d156c2dbbd66be769ea943c146458ed0860
Parents: ac4a7db
Author: James Peach <jp...@apache.org>
Authored: Tue Feb 3 12:33:54 2015 -0800
Committer: James Peach <jp...@apache.org>
Committed: Mon Feb 23 12:42:12 2015 -0800

----------------------------------------------------------------------
 CHANGES            |  2 ++
 lib/ts/ink_args.cc | 60 ++++++++++++++++++++++++++++++-------------------
 2 files changed, 39 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1d6f7d15/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index eb1619f..9511ce1 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 5.3.0
 
+  *) [TS-3403] Stop parsing command-line options at the first non-option.
+
   *) [TS-3402] Rationalize lock debugging infrastructure.
 
   *) [TS-3358] Add access checking to the management API.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1d6f7d15/lib/ts/ink_args.cc
----------------------------------------------------------------------
diff --git a/lib/ts/ink_args.cc b/lib/ts/ink_args.cc
index 9a30b12..de4fb5d 100644
--- a/lib/ts/ink_args.cc
+++ b/lib/ts/ink_args.cc
@@ -192,36 +192,50 @@ process_args(const AppVersionInfo * appinfo, const ArgumentDescription * argumen
   //
   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;
+
+    // Hack for supporting '-' as a file argument.
+    if (strcmp(*argv, "-") == 0) {
+      append_file_argument(*argv);
+      break;
+    }
+
+    // No leading '-', this is the start of the file arguments.
+    if ((*argv)[0] != '-') {
+      append_file_argument(*argv);
+      break;
+    }
+
+    if ((*argv)[1] == '-') {
+      // Deal with long options ...
+      for (i = 0; i < n_argument_descriptions; i++)
+        if (!strcmp(argument_descriptions[i].name, (*argv) + 2)) {
+          *argv += strlen(*argv) - 1;
+          process_arg(appinfo, argument_descriptions, n_argument_descriptions, i, &argv, usage_string);
+          break;
+        }
+      if (i >= n_argument_descriptions)
+        usage(argument_descriptions, n_argument_descriptions, usage_string);
+    } else {
+      // Deal with (possibly combined) short options ...
+      while (*++(*argv)) {
+        for (i = 0; i < n_argument_descriptions; i++) {
+          if (argument_descriptions[i].key == **argv) {
             process_arg(appinfo, argument_descriptions, n_argument_descriptions, i, &argv, usage_string);
             break;
           }
-        if (i >= n_argument_descriptions)
-          usage(argument_descriptions, n_argument_descriptions, usage_string);
-      } else {
-        // Hack for supporting '-' as a file argument.
-        if (strcmp(*argv, "-") == 0) {
-          append_file_argument(*argv);
         }
 
-        while (*++(*argv)) {
-          for (i = 0; i < n_argument_descriptions; i++) {
-            if (argument_descriptions[i].key == **argv) {
-              process_arg(appinfo, argument_descriptions, n_argument_descriptions, i, &argv, usage_string);
-              break;
-            }
-          }
-
-          if (i >= n_argument_descriptions) {
-            usage(argument_descriptions, n_argument_descriptions, usage_string);
-          }
+        if (i >= n_argument_descriptions) {
+          usage(argument_descriptions, n_argument_descriptions, usage_string);
         }
       }
-    } else {
+    }
+
+  }
+
+  // If we have any arguments left, slurp them up into file_arguments.
+  if (*argv) {
+    while (*++argv) {
       append_file_argument(*argv);
     }
   }