tools: nfdc command line parser

refs #3749

Change-Id: Ief301152212a6d501f0396b2c9834e860ddaf6c5
diff --git a/tools/nfdc/main.cpp b/tools/nfdc/main.cpp
index 5bc2596..85fe1e9 100644
--- a/tools/nfdc/main.cpp
+++ b/tools/nfdc/main.cpp
@@ -23,8 +23,8 @@
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "available-commands.hpp"
 #include "legacy-nfdc.hpp"
-#include "status-main.hpp"
 #include "core/version.hpp"
 
 namespace nfd {
@@ -34,29 +34,35 @@
 static int
 main(int argc, char** argv)
 {
-  if (argc < 2) {
+  std::vector<std::string> args(argv + 1, argv + argc);
+
+  if (args.empty() || args[0] == "-h") {
     legacyNfdcUsage();
     return 0;
   }
 
-  std::string subcommand(argv[1]);
-  std::vector<std::string> args(argv + 2, argv + argc);
-
-  if (subcommand == "-h") {
-    legacyNfdcUsage();
-    return 0;
-  }
-
-  if (subcommand == "-V") {
+  if (args[0] == "-V") {
     std::cout << NFD_VERSION_BUILD_STRING << std::endl;
     return 0;
   }
 
-  if (subcommand == "legacy-nfd-status") {
-    return statusMain(args);
+  CommandParser parser;
+  registerCommands(parser);
+  CommandParser::Execute* execute = nullptr;
+  CommandArguments ca;
+  try {
+    std::tie(execute, ca) = parser.parse(args, ParseMode::ONE_SHOT);
+  }
+  catch (const std::invalid_argument& e) {
+    std::cerr << e.what() << std::endl;
+    return 1;
   }
 
-  return legacyNfdcMain(subcommand, args);
+  ///\todo create Face and KeyChain here
+  (*execute)(ca);
+  ///\todo call processEvents here
+  ///\todo return proper exit code here, instead of using exit() in subcommand
+  return 0;
 }
 
 } // namespace nfdc