trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [trafficserver] branch master updated: Convert traffic_cache_tool to use ArgParser
Date Thu, 11 Oct 2018 18:29:15 GMT
This is an automated email from the ASF dual-hosted git repository.

amc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 40311fb  Convert traffic_cache_tool to use ArgParser
40311fb is described below

commit 40311fb748d07455d9cb39c811c2c780d1f7626a
Author: Xavier Chi <chitianhaoxp@gmail.com>
AuthorDate: Tue Oct 9 15:44:38 2018 -0500

    Convert traffic_cache_tool to use ArgParser
---
 src/traffic_cache_tool/CacheDefs.h  |   1 -
 src/traffic_cache_tool/CacheTool.cc | 250 +++++++++++++++---------------------
 src/traffic_cache_tool/Command.cc   | 175 -------------------------
 src/traffic_cache_tool/Command.h    | 232 ---------------------------------
 src/traffic_cache_tool/Makefile.inc |   3 +-
 5 files changed, 102 insertions(+), 559 deletions(-)

diff --git a/src/traffic_cache_tool/CacheDefs.h b/src/traffic_cache_tool/CacheDefs.h
index 08a73e4..929d37e 100644
--- a/src/traffic_cache_tool/CacheDefs.h
+++ b/src/traffic_cache_tool/CacheDefs.h
@@ -33,7 +33,6 @@
 #include <list>
 #include "tscore/CryptoHash.h"
 
-#include "Command.h"
 #include "File.h"
 
 namespace tag
diff --git a/src/traffic_cache_tool/CacheTool.cc b/src/traffic_cache_tool/CacheTool.cc
index d6218ed..bc35c2f 100644
--- a/src/traffic_cache_tool/CacheTool.cc
+++ b/src/traffic_cache_tool/CacheTool.cc
@@ -26,9 +26,7 @@
 #include <memory>
 #include <vector>
 #include <map>
-#include <getopt.h>
 #include <system_error>
-#include <cstring>
 #include <fcntl.h>
 #include <cctype>
 #include <cstring>
@@ -42,10 +40,10 @@
 #include "tscore/ink_file.h"
 #include "tscore/BufferWriter.h"
 #include "tscore/CryptoHash.h"
+#include "tscore/ArgParser.h"
 #include <thread>
 
 #include "File.h"
-#include "Command.h"
 #include "CacheDefs.h"
 #include "CacheScan.h"
 
@@ -68,7 +66,9 @@ extern int OPEN_RW_FLAG;
 const Bytes ts::CacheSpan::OFFSET{CacheStoreBlocks{1}};
 FilePath SpanFile;
 FilePath VolumeFile;
-ts::CommandTable Commands;
+ts::ArgParser parser;
+
+Errata err;
 
 namespace ct
 {
@@ -457,7 +457,7 @@ Cache::loadSpan(FilePath const &path)
 {
   Errata zret;
   if (!path.has_path()) {
-    zret = Errata::Message(0, EINVAL, "A span file specified by --span is required");
+    zret = Errata::Message(0, EINVAL, "A span file specified by --spans is required");
   } else if (!path.is_readable()) {
     zret = Errata::Message(0, EPERM, '\'', path.path(), "' is not readable.");
   } else if (path.is_regular_file()) {
@@ -1102,84 +1102,69 @@ VolumeConfig::load(FilePath const &path)
   }
   return zret;
 }
-/* ---------------------------------------------------------------------------------------
*/
-struct option Options[] = {{"help", 0, nullptr, 'h'},  {"spans", 1, nullptr, 's'}, {"volumes",
1, nullptr, 'v'},
-                           {"write", 0, nullptr, 'w'}, {"input", 1, nullptr, 'i'}, {"device",
1, nullptr, 'd'},
-                           {"aos", 1, nullptr, 'o'},   {nullptr, 0, nullptr, 0}};
 } // namespace ct
 
 using namespace ct;
-Errata
+void
 List_Stripes(Cache::SpanDumpDepth depth)
 {
-  Errata zret;
   Cache cache;
 
-  if ((zret = cache.loadSpan(SpanFile))) {
+  if ((err = cache.loadSpan(SpanFile))) {
     cache.dumpSpans(depth);
     cache.dumpVolumes();
   }
-  return zret;
 }
 
-Errata
-Cmd_Allocate_Empty_Spans(int argc, char *argv[])
+void
+Cmd_Allocate_Empty_Spans()
 {
-  Errata zret;
   VolumeAllocator va;
 
   //  OPEN_RW_FLAG = O_RDWR;
-  zret = va.load(SpanFile, VolumeFile);
-  if (zret) {
+  if ((err = va.load(SpanFile, VolumeFile))) {
     va.fillEmptySpans();
   }
-
-  return zret;
 }
 
-Errata
-Simulate_Span_Allocation(int argc, char *argv[])
+void
+Simulate_Span_Allocation()
 {
-  Errata zret;
   VolumeAllocator va;
 
   if (!VolumeFile) {
-    zret.push(0, 9, "Volume config file not set");
+    err.push(0, 9, "Volume config file not set");
   }
   if (!SpanFile) {
-    zret.push(0, 9, "Span file not set");
+    err.push(0, 9, "Span file not set");
   }
 
-  if (zret) {
-    if ((zret = va.load(SpanFile, VolumeFile)).isOK()) {
-      zret = va.fillAllSpans();
+  if (err) {
+    if ((err = va.load(SpanFile, VolumeFile)).isOK()) {
+      err = va.fillAllSpans();
       va.dumpVolumes();
     }
   }
-  return zret;
 }
 
-Errata
+void
 Clear_Spans()
 {
-  Errata zret;
   Cache cache;
 
   if (!OPEN_RW_FLAG) {
-    zret.push(0, 1, "Writing Not Enabled.. Please use --write to enable writing to disk");
-    return zret;
+    err.push(0, 1, "Writing Not Enabled.. Please use --write to enable writing to disk");
+    return;
   }
 
-  if ((zret = cache.loadSpan(SpanFile))) {
+  if ((err = cache.loadSpan(SpanFile))) {
     for (auto *span : cache._spans) {
       span->clearPermanently();
     }
   }
-
-  return zret;
 }
 
-Errata
+void
 Find_Stripe(FilePath const &input_file_path)
 {
   // scheme=http user=u password=p host=172.28.56.109 path=somepath query=somequery port=1234
@@ -1193,13 +1178,12 @@ Find_Stripe(FilePath const &input_file_path)
   //  else
   //    std::cout << h << " : is NOT valid" << std::endl;
 
-  Errata zret;
   Cache cache;
   if (input_file_path) {
     printf("passed argv %s\n", input_file_path.path());
   }
   cache.loadURLs(input_file_path);
-  if ((zret = cache.loadSpan(SpanFile))) {
+  if ((err = cache.loadSpan(SpanFile))) {
     cache.dumpSpans(Cache::SpanDumpDepth::SPAN);
     cache.build_stripe_hash_table();
     for (auto host : cache.URLset) {
@@ -1215,31 +1199,26 @@ Find_Stripe(FilePath const &input_file_path)
              stripe_->hashText.data());
     }
   }
-
-  return zret;
 }
 
-Errata
+void
 dir_check()
 {
-  Errata zret;
   Cache cache;
-  if ((zret = cache.loadSpan(SpanFile))) {
+  if ((err = cache.loadSpan(SpanFile))) {
     cache.dumpSpans(Cache::SpanDumpDepth::SPAN);
     for (auto &stripe : cache.globalVec_stripe) {
       stripe->dir_check();
     }
   }
   printf("\nCHECK succeeded\n");
-  return zret;
 }
 
-Errata
+void
 walk_bucket_chain(std::string devicePath)
 {
-  Errata zret;
   Cache cache;
-  if ((zret = cache.loadSpan(SpanFile))) {
+  if ((err = cache.loadSpan(SpanFile))) {
     cache.dumpSpans(Cache::SpanDumpDepth::SPAN);
     for (auto sp : cache._spans) {
       if (devicePath.size() > 0 && 0 == strncmp(sp->_path.path(), devicePath.data(),
devicePath.size())) {
@@ -1251,15 +1230,13 @@ walk_bucket_chain(std::string devicePath)
       }
     }
   }
-  return zret;
 }
 
-Errata
+void
 Clear_Span(std::string devicePath)
 {
-  Errata zret;
   Cache cache;
-  if ((zret = cache.loadSpan(SpanFile))) {
+  if ((err = cache.loadSpan(SpanFile))) {
     cache.dumpSpans(Cache::SpanDumpDepth::SPAN);
     for (auto sp : cache._spans) {
       if (devicePath.size() > 0 && 0 == strncmp(sp->_path.path(), devicePath.data(),
devicePath.size())) {
@@ -1268,15 +1245,14 @@ Clear_Span(std::string devicePath)
       }
     }
   }
-  return zret;
+  return;
 }
 
-Errata
+void
 Check_Freelist(std::string devicePath)
 {
-  Errata zret;
   Cache cache;
-  if ((zret = cache.loadSpan(SpanFile))) {
+  if ((err = cache.loadSpan(SpanFile))) {
     cache.dumpSpans(Cache::SpanDumpDepth::SPAN);
     for (auto sp : cache._spans) {
       if (devicePath.size() > 0 && 0 == strncmp(sp->_path.path(), devicePath.data(),
devicePath.size())) {
@@ -1292,28 +1268,24 @@ Check_Freelist(std::string devicePath)
       }
     }
   }
-  return zret;
 }
 
-Errata
+void
 Init_disk(FilePath const &input_file_path)
 {
-  Errata zret;
   Cache cache;
   VolumeAllocator va;
 
   if (!OPEN_RW_FLAG) {
-    zret.push(0, 1, "Writing Not Enabled.. Please use --write to enable writing to disk");
-    return zret;
+    err.push(0, 1, "Writing Not Enabled.. Please use --write to enable writing to disk");
+    return;
   }
 
-  zret = va.load(SpanFile, VolumeFile);
+  err = va.load(SpanFile, VolumeFile);
   va.allocateSpan(input_file_path);
-
-  return zret;
 }
 
-Errata
+void
 Get_Response(FilePath const &input_file_path)
 {
   // scheme=http user=u password=p host=172.28.56.109 path=somepath query=somequery port=1234
@@ -1322,13 +1294,12 @@ Get_Response(FilePath const &input_file_path)
 
   //  char* h= http://user:pass@IPADDRESS/path_to_file;?port      <== this is the format
we need
 
-  Errata zret;
   Cache cache;
   if (input_file_path) {
     printf("passed argv %s\n", input_file_path.path());
   }
   cache.loadURLs(input_file_path);
-  if ((zret = cache.loadSpan(SpanFile))) {
+  if ((err = cache.loadSpan(SpanFile))) {
     cache.dumpSpans(Cache::SpanDumpDepth::SPAN);
     cache.build_stripe_hash_table();
     for (auto host : cache.URLset) {
@@ -1348,8 +1319,6 @@ Get_Response(FilePath const &input_file_path)
       stripe_->dir_probe(&hashT, dir_result, nullptr);
     }
   }
-
-  return zret;
 }
 
 void static scan_span(Span *span, ts::FilePath const &regex_path)
@@ -1368,15 +1337,14 @@ void static scan_span(Span *span, ts::FilePath const &regex_path)
   }
 }
 
-Errata
+void
 Scan_Cache(ts::FilePath const &regex_path)
 {
-  Errata zret;
   Cache cache;
   std::vector<std::thread> threadPool;
-  if ((zret = cache.loadSpan(SpanFile))) {
-    if (zret.size()) {
-      return zret;
+  if ((err = cache.loadSpan(SpanFile))) {
+    if (err.size()) {
+      return;
     }
     cache.dumpSpans(Cache::SpanDumpDepth::SPAN);
     for (auto sp : cache._spans) {
@@ -1385,90 +1353,74 @@ Scan_Cache(ts::FilePath const &regex_path)
     for (auto &th : threadPool)
       th.join();
   }
-  return zret;
 }
 
 int
-main(int argc, char *argv[])
+main(int argc, const char *argv[])
 {
-  int opt_idx = 0;
-  int opt_val;
-  bool help = false;
   FilePath input_url_file;
   std::string inputFile;
-  char *inp = nullptr;
-  while (-1 != (opt_val = getopt_long(argc, argv, "h", Options, &opt_idx))) {
-    switch (opt_val) {
-    case 'h':
-      printf("Usage: %s --span <SPAN> --volume <FILE> <COMMAND> [<SUBCOMMAND>
...]\n", argv[0]);
-      help = true;
-      break;
-    case 's':
-      SpanFile = optarg;
-      break;
-    case 'v':
-      VolumeFile = optarg;
-      break;
-    case 'w':
-      OPEN_RW_FLAG = O_RDWR;
-      std::cout << "NOTE: Writing to physical devices enabled" << std::endl;
-      break;
-    case 'i':
-      input_url_file = optarg;
-      break;
-    case 'o':
-      cache_config_min_average_object_size = atoi(optarg);
-      break;
-    case 'd':
-      if (!inp) {
-        inp = strdup(optarg);
-        inputFile.assign(inp, strlen(inp));
-      }
-      break;
-    }
-  }
 
-  Commands.add("list", "List elements of the cache", []() { return List_Stripes(Cache::SpanDumpDepth::SPAN);
})
-    .subCommand(std::string("stripes"), std::string("List the stripes"),
-                []() { return List_Stripes(Cache::SpanDumpDepth::STRIPE); });
-  Commands.add(std::string("clear"), std::string("Clear spans"), []() { return Clear_Spans();
})
-    .subCommand(std::string("span"), std::string("clear an specific span"),
-                [&](int, char *argv[]) { return Clear_Span(inputFile); });
-
-  auto &c = Commands.add(std::string("dir_check"), std::string("cache check"));
-  c.subCommand(std::string("full"), std::string("Full report of the cache storage"), &dir_check);
-  c.subCommand(std::string("freelist"), std::string("check the freelist for loop"),
-               [&](int, char *argv[]) { return Check_Freelist(inputFile); });
-  c.subCommand(std::string("bucket_chain"), std::string("walk bucket chains for loops"),
-               [&](int, char *argv[]) { return walk_bucket_chain(inputFile); });
-  Commands.add(std::string("volumes"), std::string("Volumes"), &Simulate_Span_Allocation);
-  Commands.add(std::string("alloc"), std::string("Storage allocation"))
-    .subCommand(std::string("free"), std::string("Allocate storage on free (empty) spans"),
&Cmd_Allocate_Empty_Spans);
-  Commands.add(std::string("find"), std::string("Find Stripe Assignment"),
-               [&](int, char *argv[]) { return Find_Stripe(input_url_file); });
-  Commands.add(std::string("clearspan"), std::string("clear specific span"))
-    .subCommand(std::string("span"), std::string("device path"), [&](int, char *argv[])
{ return Clear_Span(inputFile); });
-  Commands.add(std::string("retrieve"), std::string(" retrieve the response of the given
list of URLs"),
-               [&](int, char *argv[]) { return Get_Response(input_url_file); });
-  Commands.add(std::string("init"), std::string(" Initializes uninitialized span"),
-               [&](int, char *argv[]) { return Init_disk(input_url_file); });
-  Commands.add(std::string("scan"), std::string(" Scans the whole cache and lists the urls
of the cached contents"),
-               [&](int, char *argv[]) { return Scan_Cache(input_url_file); });
-  Commands.setArgIndex(optind);
-
-  if (help) {
-    Commands.helpMessage(argc - 1, argv + 1);
+  parser.add_global_usage(std::string(argv[0]) + " --spans <SPAN> --volume <FILE>
<COMMAND> [<SUBCOMMAND> ...]\n");
+  parser.require_commands()
+    .add_option("--help", "-h", "")
+    .add_option("--spans", "-s", "", "", 1)
+    .add_option("--volumes", "-v", "", "", 1)
+    .add_option("--write", "-w", "")
+    .add_option("--input", "-i", "", "", 1)
+    .add_option("--device", "-d", "", "", 1)
+    .add_option("--aos", "-o", "", "", 1);
+
+  parser.add_command("list", "List elements of the cache", []() { List_Stripes(Cache::SpanDumpDepth::SPAN);
})
+    .add_command("stripes", "List the stripes", []() { List_Stripes(Cache::SpanDumpDepth::STRIPE);
});
+  parser.add_command("clear", "Clear spans", []() { Clear_Spans(); }).add_command("span",
"clear an specific span", [&]() {
+    Clear_Span(inputFile);
+  });
+  auto &c = parser.add_command("dir_check", "cache check").require_commands();
+  c.add_command("full", "Full report of the cache storage", &dir_check);
+  c.add_command("freelist", "check the freelist for loop", [&]() { Check_Freelist(inputFile);
});
+  c.add_command("bucket_chain", "walk bucket chains for loops", [&]() { walk_bucket_chain(inputFile);
});
+  parser.add_command("volumes", "Volumes", &Simulate_Span_Allocation);
+  parser.add_command("alloc", "Storage allocation")
+    .require_commands()
+    .add_command("free", "Allocate storage on free (empty) spans", &Cmd_Allocate_Empty_Spans);
+  parser.add_command("find", "Find Stripe Assignment", [&]() { Find_Stripe(input_url_file);
});
+  parser.add_command("clearspan", "clear specific span").add_command("span", "device path",
[&]() { Clear_Span(inputFile); });
+  parser.add_command("retrieve", " retrieve the response of the given list of URLs", [&]()
{ Get_Response(input_url_file); });
+  parser.add_command("init", " Initializes uninitialized span", [&]() { Init_disk(input_url_file);
});
+  parser.add_command("scan", " Scans the whole cache and lists the urls of the cached contents",
+                     [&]() { Scan_Cache(input_url_file); });
+
+  // parse the arguments
+  auto arguments = parser.parse(argv);
+  if (auto data = arguments.get("spans")) {
+    SpanFile = data.value().c_str();
+  }
+  if (auto data = arguments.get("volumes")) {
+    VolumeFile = data.value().c_str();
+  }
+  if (auto data = arguments.get("input")) {
+    input_url_file = data.value().c_str();
+  }
+  if (auto data = arguments.get("aos")) {
+    cache_config_min_average_object_size = std::stoi(data.value());
+  }
+  if (auto data = arguments.get("device")) {
+    inputFile = data.value();
+  }
+  if (auto data = arguments.get("write")) {
+    OPEN_RW_FLAG = O_RDWR;
+    std::cout << "NOTE: Writing to physical devices enabled" << std::endl;
+  }
+
+  if (arguments.has_action()) {
+    arguments.invoke();
+  }
+
+  if (err.size()) {
+    std::cerr << err;
     exit(1);
   }
 
-  Errata result = Commands.invoke(argc, argv);
-
-  if (result.size()) {
-    std::cerr << result;
-    exit(1);
-  }
-  if (inp) {
-    free(inp);
-  }
   return 0;
 }
diff --git a/src/traffic_cache_tool/Command.cc b/src/traffic_cache_tool/Command.cc
deleted file mode 100644
index 1fe7a73..0000000
--- a/src/traffic_cache_tool/Command.cc
+++ /dev/null
@@ -1,175 +0,0 @@
-/** @file
-
-    Nest commands (for command line processing).
-
-    @section license License
-
-    Licensed to the Apache Software Foundation (ASF) under one
-    or more contributor license agreements.  See the NOTICE file
-    distributed with this work for additional information
-    regarding copyright ownership.  The ASF licenses this file
-    to you under the Apache License, Version 2.0 (the
-    "License"); you may not use this file except in compliance
-    with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
- */
-
-#include "Command.h"
-#include <new>
-#include <algorithm>
-#include <cstring>
-#include <sstream>
-
-namespace ts
-{
-int CommandTable::_opt_idx = 0;
-
-static const std::string LEADING(":-  ");
-
-// Error message functions.
-ts::Errata
-ERR_COMMAND_TAG_NOT_FOUND(char const *tag)
-{
-  std::ostringstream s;
-  s << "Command tag " << tag << " not found";
-  return ts::Errata(s.str());
-}
-
-CommandTable::Command::Command() {}
-
-CommandTable::Command::Command(std::string const &name, std::string const &help)
: _name(name), _help(help) {}
-
-CommandTable::Command::Command(std::string const &name, std::string const &help,
LeafAction const &f) : _name(name), _help(help)
-{
-  _action = f;
-}
-
-CommandTable::Command::Command(std::string const &name, std::string const &help,
NullaryAction const &f) : _name(name), _help(help)
-{
-  _action = f;
-}
-
-CommandTable::Command::~Command() {}
-
-CommandTable::Command &
-CommandTable::Command::subCommand(std::string const &name, std::string const &help,
LeafAction const &f)
-{
-  _group.push_back(Command(name, help, f));
-  return _group.back();
-}
-
-CommandTable::Command &
-CommandTable::Command::subCommand(std::string const &name, std::string const &help,
NullaryAction const &f)
-{
-  _group.push_back(Command(name, help, f));
-  return _group.back();
-}
-
-auto
-CommandTable::Command::subCommand(std::string const &name, std::string const &help)
-> self &
-{
-  _group.push_back(Command(name, help));
-  return _group.back();
-}
-
-ts::Errata
-CommandTable::Command::invoke(int argc, char *argv[])
-{
-  ts::Errata zret;
-
-  if (_action.is_leaf()) {
-    zret = _action.invoke(argc - CommandTable::_opt_idx, argv + CommandTable::_opt_idx);
-  } else if (CommandTable::_opt_idx >= argc || argv[CommandTable::_opt_idx][0] == '-')
{
-    if (_action.is_nullary()) {
-      zret = _action.invoke();
-    } else {
-      std::ostringstream s;
-      s << "Incomplete command, additional keyword required";
-      s << std::endl;
-      this->helpMessage(0, nullptr, s, LEADING);
-      zret.push(s.str());
-    }
-  } else {
-    char const *tag = argv[CommandTable::_opt_idx];
-    auto spot       = std::find_if(_group.begin(), _group.end(),
-                             [tag](CommandGroup::value_type const &elt) { return 0 ==
strcasecmp(tag, elt._name.c_str()); });
-    if (spot != _group.end()) {
-      ++CommandTable::_opt_idx;
-      zret = spot->invoke(argc, argv);
-    } else {
-      zret = ERR_COMMAND_TAG_NOT_FOUND(tag);
-    }
-  }
-  return zret;
-}
-
-void
-CommandTable::Command::helpMessage(int argc, char *argv[], std::ostream &out, std::string
const &prefix) const
-{
-  if (CommandTable::_opt_idx >= argc || argv[CommandTable::_opt_idx][0] == '-') {
-    // Tail of command keywords, start listing
-    if (_name.empty()) { // root command group, don't print for that.
-      for (Command const &c : _group) {
-        c.helpMessage(argc, argv, out, prefix);
-      }
-    } else {
-      out << prefix << _name << ": " << _help << std::endl;
-      for (Command const &c : _group) {
-        c.helpMessage(argc, argv, out, "  " + prefix);
-      }
-    }
-  } else {
-    char const *tag = argv[CommandTable::_opt_idx];
-    auto spot       = std::find_if(_group.begin(), _group.end(),
-                             [tag](CommandGroup::value_type const &elt) { return 0 ==
strcasecmp(tag, elt._name.c_str()); });
-    if (spot != _group.end()) {
-      ++CommandTable::_opt_idx;
-      spot->helpMessage(argc, argv, out, prefix);
-    } else {
-      out << ERR_COMMAND_TAG_NOT_FOUND(tag) << std::endl;
-    }
-  }
-}
-
-CommandTable::CommandTable() {}
-
-auto
-CommandTable::add(std::string const &name, std::string const &help) -> Command
&
-{
-  return _top.subCommand(name, help);
-}
-
-auto
-CommandTable::add(std::string const &name, std::string const &help, LeafAction const
&f) -> Command &
-{
-  return _top.subCommand(name, help, f);
-}
-
-auto
-CommandTable::add(std::string const &name, std::string const &help, NullaryAction
const &f) -> Command &
-{
-  return _top.subCommand(name, help, f);
-}
-
-ts::Errata
-CommandTable::invoke(int argc, char *argv[])
-{
-  return _top.invoke(argc, argv);
-}
-
-// This is basically cloned from invoke(), need to find how to do some unification.
-void
-CommandTable::helpMessage(int argc, char *argv[]) const
-{
-  _opt_idx = 0;
-  std::cerr << "Command tree" << std::endl;
-  _top.helpMessage(argc, argv, std::cerr, LEADING);
-}
-} // namespace ts
diff --git a/src/traffic_cache_tool/Command.h b/src/traffic_cache_tool/Command.h
deleted file mode 100644
index 9c877f7..0000000
--- a/src/traffic_cache_tool/Command.h
+++ /dev/null
@@ -1,232 +0,0 @@
-/** @file
-
-    Command registration.
-
-    @section license License
-
-    Licensed to the Apache Software Foundation (ASF) under one
-    or more contributor license agreements.  See the NOTICE file
-    distributed with this work for additional information
-    regarding copyright ownership.  The ASF licenses this file
-    to you under the Apache License, Version 2.0 (the
-    "License"); you may not use this file except in compliance
-    with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
- */
-
-#include <vector>
-#include <functional>
-#include <string>
-#include <iostream>
-#include <memory.h>
-#include <tsconfig/Errata.h>
-
-#pragma once
-namespace ts
-{
-// Because in C+11 std::max is not constexpr
-template <typename I>
-constexpr inline I
-maximum(I lhs, I rhs)
-{
-  return lhs < rhs ? rhs : lhs;
-}
-
-/// Top level container for commands.
-class CommandTable
-{
-  typedef CommandTable self; ///< Self reference type.
-public:
-  /// Signature for a leaf command.
-  using LeafAction = std::function<ts::Errata(int argc, char *argv[])>;
-  /// Signature for a argumentless command.
-  using NullaryAction = std::function<ts::Errata()>;
-
-  CommandTable();
-
-  /// A command.
-  /// This is either a leaf (and has a function for an implementation) or it is a group
-  /// of nested commands.
-  class Command
-  {
-    typedef Command self; ///< Self reference type.
-  public:
-    Command(Command &&that) = default;
-    ~Command();
-
-    /** Add a subcommand to this command.
-        @return The subcommand object.
-    */
-    Command &subCommand(std::string const &name, std::string const &help);
-    /** Add a subcommand to this command.
-        @return The new sub command instance.
-    */
-    Command &subCommand(std::string const &name, std::string const &help, NullaryAction
const &f);
-    /** Add a leaf command.
-        @return This new sub command instance.
-    */
-    Command &subCommand(std::string const &name, std::string const &help, LeafAction
const &f);
-
-    /** Invoke a command.
-        @return The return value of the executed command, or an error value if the command
was not found.
-    */
-    ts::Errata invoke(int argc, char *argv[]);
-
-    void helpMessage(int argc, char *argv[], std::ostream &out = std::cerr, std::string
const &prefix = std::string()) const;
-
-  protected:
-    typedef std::vector<Command> CommandGroup;
-
-    std::string _name; ///< Command name.
-    std::string _help; ///< Help message.
-
-    /** Class to hold varying types of functions.
-
-        @internal A bit ugly, I need to do better wrapping and type erasure.
-    */
-    class Action
-    {
-    public:
-      /// Type of the function stored.
-      enum Type {
-        NIL,     ///< Nothing / empty
-        LEAF,    ///< Leaf action (arguments)
-        NULLARY, ///< Nullary action.
-      };
-      Action() {}
-      Action(Action &&that)
-      {
-        _type = that._type;
-        memcpy(_data, that._data, sizeof(_data));
-        that._type = NIL;
-      }
-      ~Action() { this->clear(); }
-
-      Action &
-      operator=(LeafAction const &a)
-      {
-        this->clear();
-        _type = LEAF;
-        new (_data) LeafAction(a);
-        return *this;
-      }
-
-      Action &
-      operator=(NullaryAction const &a)
-      {
-        this->clear();
-        _type = NULLARY;
-        new (_data) NullaryAction(a);
-        return *this;
-      }
-
-      Errata
-      invoke(int argc, char *argv[])
-      {
-        assert(LEAF == _type);
-        return (*reinterpret_cast<LeafAction *>(_data))(argc, argv);
-      }
-
-      Errata
-      invoke()
-      {
-        assert(NULLARY == _type);
-        return (*reinterpret_cast<NullaryAction *>(_data))();
-      }
-
-      bool
-      is_leaf() const
-      {
-        return LEAF == _type;
-      }
-      bool
-      is_nullary() const
-      {
-        return NULLARY == _type;
-      }
-
-    protected:
-      void
-      clear()
-      {
-        switch (_type) {
-        case NIL:
-          break;
-        case LEAF:
-          reinterpret_cast<LeafAction *>(_data)->~LeafAction();
-          break;
-        case NULLARY:
-          reinterpret_cast<NullaryAction *>(_data)->~NullaryAction();
-          break;
-        }
-        _type = NIL;
-      }
-
-      Type _type = NIL; ///< Type of function stored.
-      /// Raw storage for the function.
-      char _data[sizeof(NullaryAction) > sizeof(LeafAction) ? sizeof(NullaryAction) :
sizeof(LeafAction)];
-    } _action;
-
-    /// Next command for current keyword.
-    CommandGroup _group;
-
-    /// Default constructor, no execution logic.
-    Command();
-    /// Construct with a function for this command.
-    Command(std::string const &name, std::string const &help);
-    /// Construct with a function for this command.
-    Command(std::string const &name, std::string const &help, LeafAction const &f);
-    /// Construct with a function for this command.
-    Command(std::string const &name, std::string const &help, NullaryAction const
&f);
-
-    friend class CommandTable;
-  };
-
-  /** Add a direct command.
-      @return The created @c Command instance.
-   */
-  Command &add(std::string const &name, std::string const &help, LeafAction const
&f);
-
-  /** Add a direct command.
-      @return The created @c Command instance.
-   */
-  Command &add(std::string const &name, std::string const &help, NullaryAction
const &f);
-
-  /** Add a parent command.
-      @return The created @c Command instance.
-  */
-  Command &add(std::string const &name, std::string const &help);
-
-  /** Set the index of the "first" argument.
-      This causes the command processing to skip @a n arguments.
-  */
-  self &setArgIndex(int n);
-
-  /** Invoke a command.
-      @return The return value of the executed command, or an error value if the command
was not found.
-  */
-  ts::Errata invoke(int argc, char *argv[]);
-
-  void helpMessage(int argc, char *argv[]) const;
-
-protected:
-  Command _top;
-  static int _opt_idx;
-
-  friend class Command;
-};
-
-inline CommandTable &
-CommandTable::setArgIndex(int n)
-{
-  _opt_idx = n;
-  return *this;
-}
-} // namespace ts
diff --git a/src/traffic_cache_tool/Makefile.inc b/src/traffic_cache_tool/Makefile.inc
index 8b3dfb4..9e24ab9 100644
--- a/src/traffic_cache_tool/Makefile.inc
+++ b/src/traffic_cache_tool/Makefile.inc
@@ -31,12 +31,11 @@ traffic_cache_tool_traffic_cache_tool_SOURCES = \
     traffic_cache_tool/CacheTool.cc \
     traffic_cache_tool/File.h \
     traffic_cache_tool/File.cc \
-    traffic_cache_tool/Command.h \
-    traffic_cache_tool/Command.cc \
     traffic_cache_tool/CacheScan.h \
     traffic_cache_tool/CacheScan.cc
 
 traffic_cache_tool_traffic_cache_tool_LDADD = \
+    $(top_builddir)/src/tscore/.libs/ArgParser.o \
     $(top_builddir)/src/tscore/.libs/ink_assert.o \
     $(top_builddir)/src/tscore/.libs/ink_code.o \
     $(top_builddir)/src/tscore/.libs/ink_error.o \


Mime
View raw message