tools: nfdc help command

refs #3780

Change-Id: Ibd0e37bad127a38e582864fadd81afadc74baf48
diff --git a/docs/conf.py b/docs/conf.py
index 89dc2a0..2f81985 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -62,7 +62,7 @@
 
 # General information about the project.
 project = u'NFD - Named Data Networking Forwarding Daemon'
-copyright = u'2014, Named Data Networking Project'
+copyright = u'2014-2016, Named Data Networking Project'
 
 # The version info for the project you're documenting, acts as replacement for
 # |version| and |release|, also used in various other places throughout the
@@ -247,8 +247,11 @@
         u'NDN auto-configuration client', None, 1),
     ('manpages/ndn-autoconfig.conf', 'ndn-autoconfig.conf',
         u'NDN auto-configuration client configuration file', None, 5),
-    ('manpages/nfdc', 'nfdc',
-        u'NFD utility to manipulate the forwarding table (FIB)', None, 1),
+    ('manpages/nfdc', 'nfdc', u'show / manipulate NFD state and configuration', None, 1),
+    ('manpages/nfdc-status', 'nfdc-status', u'show NFD status', None, 1),
+    ('manpages/nfdc-face', 'nfdc-face', u'show and manipulate NFD faces', None, 1),
+    ('manpages/nfdc-route', 'nfdc-route', u'show and manipulate NFD routes', None, 1),
+    ('manpages/nfdc-strategy', 'nfdc-strategy', u'show and manipulate NFD strategy choices', None, 1),
     ('manpages/nfd-autoreg', 'nfd-autoreg', u'NFD Auto-registration Server', None, 1),
     ('manpages/nfd-status-http-server', 'nfd-status-http-server',
         u'NFD status HTTP server', None, 1),
diff --git a/docs/manpages.rst b/docs/manpages.rst
index 7207f34..0dd78eb 100644
--- a/docs/manpages.rst
+++ b/docs/manpages.rst
@@ -6,6 +6,10 @@
 .. toctree::
    manpages/nfd
    manpages/nfdc
+   manpages/nfdc-status
+   manpages/nfdc-face
+   manpages/nfdc-route
+   manpages/nfdc-strategy
    manpages/nfd-status
    schema
    manpages/nfd-status-http-server
diff --git a/docs/manpages/nfdc-face.rst b/docs/manpages/nfdc-face.rst
new file mode 100644
index 0000000..8233364
--- /dev/null
+++ b/docs/manpages/nfdc-face.rst
@@ -0,0 +1,51 @@
+nfdc-face
+=========
+
+SYNOPSIS
+--------
+| nfdc face [list]
+| nfdc channel [list]
+| nfdc create [-P] <faceUri>
+| nfdc destroy <faceId|faceUri>
+
+DESCRIPTION
+-----------
+In NFD, a face is the generalization of network interface.
+It could be a physical network interface to communicate on a physical link,
+an overlay communication channel between NFD and a remote node,
+or an inter-process communication channel between NFD and a local application.
+
+The **nfdc face list** command shows a list of faces, their properties, and statistics.
+
+The **nfdc channel list** command shows a list of channels.
+Channels are listening sockets that can accept incoming connections and create new faces.
+
+The **nfdc create** command creates a new UDP or TCP face.
+
+The **nfdc destroy** command destroys an existing face.
+It has no effect if the specified face does not exist.
+
+OPTIONS
+-------
+-P
+    Creates a "permanent" rather than persistent face.
+    A persistent face is closed when a socket error occrs.
+    A permanent face is kept alive upon socket errors,
+    and is closed only upon **nfdc destroy** command.
+
+<faceUri>
+    An URI representing the remote endpoint of a face.
+    Its syntax is:
+
+    - udp[4|6]://<IP-or-host>[:<port>]
+    - tcp[4|6]://<IP-or-host>[:<port>]
+
+    When a hostname is specified, a DNS query is used to obtain the IP address.
+
+<faceId>
+    Numerical identifier of the face.
+    It is displayed in the output of **nfdc face list** and **nfdc create** commands.
+
+SEE ALSO
+--------
+nfd(1), nfdc(1)
diff --git a/docs/manpages/nfdc-route.rst b/docs/manpages/nfdc-route.rst
new file mode 100644
index 0000000..b654f8f
--- /dev/null
+++ b/docs/manpages/nfdc-route.rst
@@ -0,0 +1,64 @@
+nfdc-route
+==========
+
+SYNOPSIS
+--------
+| nfdc route [list]
+| nfdc fib [list]
+| nfdc register [-I] [-C] [-c <cost>] [-e <expiration>] [-o <origin>] <prefix> <faceId|faceUri>
+| nfdc unregister [-o <origin>] <prefix> <faceId>
+
+DESCRIPTION
+-----------
+In NFD, the routing information base (RIB) stores static or dynamic routing information
+registered by applications, operators, and NFD itself.
+Each *route* in the RIB indicates that contents under a name prefix may be available via a nexthop.
+A route contains a name prefix, a nexthop face, the origin, a cost, and a set of route inheritance flags;
+refer to NFD Management protocol for more information.
+
+The **nfdc route list** command shows a list of routes in the RIB.
+
+The **nfdc fib list** command shows the forwarding information base (FIB),
+which is calculated from RIB routes and used directly by NFD forwarding.
+
+The **nfdc register** command adds a new route.
+If a route with the same prefix, nexthop, and origin already exists,
+it is updated with the specified cost, expiration, and route inheritance flags.
+
+The **nfdc unregister** command removes a route with matching prefix, nexthop, and origin.
+
+OPTIONS
+-------
+-I
+    Unset CHILD_INHERIT flag in the route.
+
+-C
+    Set CAPTURE flag in the route.
+
+-c <cost>
+    The administrative cost of the route.
+    The default is 0.
+
+-e <expiration>
+    Expiration time of the route, in milliseconds.
+    When the route expires, NFD removes it from the RIB.
+    The default is infinite, which keeps the route active until the nexthop face is destroyed.
+
+-o <origin>
+    Origin of the route, i.e. who is announcing the route.
+    The default is 255, indicating a static route.
+
+<prefix>
+    Name prefix of the route.
+
+<faceUri>
+    An URI representing the remote endpoint of a face.
+    It can be used in **nfdc register** to create a new UDP or TCP face.
+
+<faceId>
+    A numerical identifier of the face.
+    It is displayed in the output of **nfdc face list** and **nfdc create** commands.
+
+SEE ALSO
+--------
+nfd(1), nfdc(1)
diff --git a/docs/manpages/nfdc-status.rst b/docs/manpages/nfdc-status.rst
new file mode 100644
index 0000000..10d1078
--- /dev/null
+++ b/docs/manpages/nfdc-status.rst
@@ -0,0 +1,31 @@
+nfdc-status
+===========
+
+SYNOPSIS
+--------
+| nfdc status [show]
+| nfdc status report [<format>]
+
+DESCRIPTION
+-----------
+The **nfdc status show** command shows general status of NFD, including its version,
+uptime, data structure counters, and global packet counters.
+
+The **nfdc status report** command generates a comprehensive report of NFD status, including:
+
+- general status (individually available from **nfdc status show**)
+- list of channels (individually available from **nfdc channel list**)
+- list of faces (individually available from **nfdc face list**)
+- list of FIB entries (individually available from **nfdc fib list**)
+- list of RIB entries (individually available from **nfdc route list**)
+- list of strategy choices (individually available from **nfdc strategy list**)
+
+OPTIONS
+-------
+<format>
+    The format of NFD status report, either ``text`` or ``xml``.
+    The default is ``text``.
+
+SEE ALSO
+--------
+nfdc(1), nfdc-channel(1), nfdc-face(1), nfdc-fib(1), nfdc-route(1), nfdc-strategy(1)
diff --git a/docs/manpages/nfdc-strategy.rst b/docs/manpages/nfdc-strategy.rst
new file mode 100644
index 0000000..1f1c292
--- /dev/null
+++ b/docs/manpages/nfdc-strategy.rst
@@ -0,0 +1,44 @@
+nfdc-strategy
+=============
+
+SYNOPSIS
+--------
+| nfdc strategy [list]
+| nfdc set-strategy <prefix> <strategy>
+| nfdc unset-strategy <prefix>
+
+DESCRIPTION
+-----------
+In NFD, packet forwarding behavior is determined by forwarding pipelines and forwarding strategies.
+The forwarding pipelines define general steps of packet processing.
+Forwarding strategies provide the intelligence to make decision on whether, when, and where
+to forward Interests.
+
+NFD contains multiple forwarding strategy implementations.
+The strategy choice table determines which strategy is used in forwarding an Interest.
+
+The **nfdc strategy list** command shows the strategy choices.
+
+The **nfdc set-strategy** command sets the strategy for a name prefix.
+
+The **nfdc unset-strategy** command clears the strategy choice at a name prefix,
+so that a strategy choice at a shorter prefix or the default strategy will be used.
+It undoes a prior **nfdc set-strategy** command on the same name prefix.
+
+OPTIONS
+-------
+<prefix>
+    The name prefix of a strategy choice.
+    The strategy choice is effective for all Interests under the name prefix,
+    unless overridden by another strategy choice.
+    Specifying ``ndn:/`` as the prefix in **nfdc set-strategy** changes the default strategy.
+    Specifying ``ndn:/`` as the prefix in **nfdc unset-strategy** is disallowed,
+    because NFD must always have a default strategy.
+
+<strategy>
+    A name that identifies the forwarding strategy.
+    Consult NFD Developer's Guide for a complete list of all implemented strategies.
+
+SEE ALSO
+--------
+nfd(1), nfdc(1)
diff --git a/tests/tools/nfdc/format-helpers.t.cpp b/tests/tools/nfdc/format-helpers.t.cpp
index f380544..99f6966 100644
--- a/tests/tools/nfdc/format-helpers.t.cpp
+++ b/tests/tools/nfdc/format-helpers.t.cpp
@@ -52,6 +52,14 @@
 
 BOOST_AUTO_TEST_SUITE(Text)
 
+BOOST_AUTO_TEST_CASE(Space)
+{
+  output_test_stream os;
+  os << 'A' << text::Spaces{-1} << 'B' << text::Spaces{0} << 'C' << text::Spaces{5} << 'D';
+
+  BOOST_CHECK(os.is_equal("ABC     D"));
+}
+
 BOOST_AUTO_TEST_CASE(Sep)
 {
   output_test_stream os;
diff --git a/tools/nfdc/available-commands.cpp b/tools/nfdc/available-commands.cpp
index b0a118a..3cd540a 100644
--- a/tools/nfdc/available-commands.cpp
+++ b/tools/nfdc/available-commands.cpp
@@ -24,6 +24,7 @@
  */
 
 #include "available-commands.hpp"
+#include "help.hpp"
 #include "status-report.hpp"
 #include "status-main.hpp"
 #include "legacy-nfdc.hpp"
@@ -62,8 +63,11 @@
 void
 registerCommands(CommandParser& parser)
 {
+  registerHelpCommand(parser);
+
   CommandDefinition defStatusReport("status", "report");
   defStatusReport
+    .setTitle("print NFD status report")
     .addArg("format", ArgValueType::REPORT_FORMAT, Required::NO, Positional::YES);
   parser.addCommand(defStatusReport, &statusReport);
 
@@ -72,17 +76,19 @@
     std::string noun;
     std::string verb;
     std::string legacyOption;
+    std::string title;
   };
   const std::vector<StatusCommandDefinition> statusCommands{
-    {"status", "show", "-v"},
-    {"face", "list", "-f"},
-    {"channel", "list", "-c"},
-    {"strategy", "list", "-s"},
-    {"fib", "list", "-b"},
-    {"route", "list", "-r"}
+    {"status", "show", "-v", "print general status"},
+    {"face", "list", "-f", "print face list"},
+    {"channel", "list", "-c", "print channel list"},
+    {"strategy", "list", "-s", "print strategy choices"},
+    {"fib", "list", "-b", "print FIB entries"},
+    {"route", "list", "-r", "print RIB routes"}
   };
   for (const StatusCommandDefinition& scd : statusCommands) {
     CommandDefinition def(scd.noun, scd.verb);
+    def.setTitle(scd.title);
     parser.addCommand(def, bind(&statusList, _1, scd.legacyOption));
   }
   parser.addAlias("status", "show", "list");
@@ -90,20 +96,26 @@
   CommandDefinition defLegacyNfdStatus("legacy-nfd-status", "");
   defLegacyNfdStatus
     .addArg("args", ArgValueType::ANY, Required::NO, Positional::YES);
-  parser.addCommand(defLegacyNfdStatus, &legacyNfdStatus);
+  parser.addCommand(defLegacyNfdStatus, &legacyNfdStatus, AVAILABLE_IN_ALL & ~AVAILABLE_IN_HELP);
 
-  const std::vector<std::string> legacyNfdcSubcommands{
-    "register",
-    "unregister",
-    "create",
-    "destroy",
-    "set-strategy",
-    "unset-strategy",
-    "add-nexthop",
-    "remove-nexthop"
+  struct LegacyNfdcCommandDefinition
+  {
+    std::string subcommand;
+    std::string title;
   };
-  for (const std::string& subcommand : legacyNfdcSubcommands) {
-    CommandDefinition def(subcommand, "");
+  const std::vector<LegacyNfdcCommandDefinition> legacyNfdcSubcommands{
+    {"register", "register a prefix"},
+    {"unregister", "unregister a prefix"},
+    {"create", "create a face"},
+    {"destroy", "destroy a face"},
+    {"set-strategy", "set strategy choice on namespace"},
+    {"unset-strategy", "unset strategy choice on namespace"},
+    {"add-nexthop", "add FIB nexthop"},
+    {"remove-nexthop", "remove FIB nexthop"}
+  };
+  for (const LegacyNfdcCommandDefinition& lncd : legacyNfdcSubcommands) {
+    CommandDefinition def(lncd.subcommand, "");
+    def.setTitle(lncd.title);
     def.addArg("args", ArgValueType::ANY, Required::NO, Positional::YES);
     parser.addCommand(def, &legacyNfdcMain);
   }
diff --git a/tools/nfdc/command-definition.hpp b/tools/nfdc/command-definition.hpp
index 136f5c4..47c6af3 100644
--- a/tools/nfdc/command-definition.hpp
+++ b/tools/nfdc/command-definition.hpp
@@ -142,20 +142,21 @@
   }
 
 public: // help
-  /** \return one-line synopsis
+  /** \return one-line description
    */
   const std::string&
-  getSynopsis() const
+  getTitle() const
   {
-    return m_synopsis;
+    return m_title;
   }
 
-  /** \brief set one-line synopsis
+  /** \brief set one-line description
+   *  \param title one-line description, written in lower case
    */
   CommandDefinition&
-  setSynopsis(const std::string& synopsis)
+  setTitle(const std::string& title)
   {
-    m_synopsis = synopsis;
+    m_title = title;
     return *this;
   }
 
@@ -189,7 +190,7 @@
   std::string m_noun;
   std::string m_verb;
 
-  std::string m_synopsis;
+  std::string m_title;
 
   struct Arg
   {
diff --git a/tools/nfdc/command-parser.cpp b/tools/nfdc/command-parser.cpp
index 6b21d8b..b4c4558 100644
--- a/tools/nfdc/command-parser.cpp
+++ b/tools/nfdc/command-parser.cpp
@@ -47,6 +47,9 @@
   if ((modes & AVAILABLE_IN_BATCH) != 0) {
     os << sep << "batch";
   }
+  if ((modes & AVAILABLE_IN_HELP) == 0) {
+    os << sep << "hidden";
+  }
 
   if (sep.getCount() == 0) {
     os << "none";
@@ -73,6 +76,11 @@
   BOOST_ASSERT(modes != AVAILABLE_IN_NONE);
   m_commands[{def.getNoun(), def.getVerb()}].reset(
     new Command{def, execute, static_cast<AvailableIn>(modes)});
+
+  if ((modes & AVAILABLE_IN_HELP) != 0) {
+    m_commandOrder.push_back(m_commands.find({def.getNoun(), def.getVerb()}));
+  }
+
   return *this;
 }
 
@@ -83,6 +91,20 @@
   return *this;
 }
 
+std::vector<const CommandDefinition*>
+CommandParser::listCommands(const std::string& noun, ParseMode mode) const
+{
+  std::vector<const CommandDefinition*> results;
+  for (CommandContainer::const_iterator i : m_commandOrder) {
+    const Command& command = *i->second;
+    if ((command.modes & static_cast<AvailableIn>(mode)) != 0 &&
+        (noun.empty() || noun == command.def.getNoun())) {
+      results.push_back(&command.def);
+    }
+  }
+  return results;
+}
+
 std::tuple<std::string, std::string, CommandArguments, ExecuteCommand>
 CommandParser::parse(const std::vector<std::string>& tokens, ParseMode mode) const
 {
diff --git a/tools/nfdc/command-parser.hpp b/tools/nfdc/command-parser.hpp
index a46530d..551f5e3 100644
--- a/tools/nfdc/command-parser.hpp
+++ b/tools/nfdc/command-parser.hpp
@@ -40,6 +40,7 @@
   AVAILABLE_IN_NONE     = 0,
   AVAILABLE_IN_ONE_SHOT = 1 << 0, ///< one-shot mode
   AVAILABLE_IN_BATCH    = 1 << 1, ///< batch mode
+  AVAILABLE_IN_HELP     = 1 << 7, ///< visible in help listing
   AVAILABLE_IN_ALL      = 0xff
 };
 
@@ -86,6 +87,14 @@
   CommandParser&
   addAlias(const std::string& noun, const std::string& verb, const std::string& verb2);
 
+  /** \brief list known commands for help
+   *  \param noun if not empty, filter results by this noun
+   *  \param mode include commands for the specified parse mode
+   *  \return commands in insertion order
+   */
+  std::vector<const CommandDefinition*>
+  listCommands(const std::string& noun, ParseMode mode) const;
+
   /** \brief parse a command line
    *  \param tokens command line
    *  \param mode parser mode, must be ParseMode::ONE_SHOT, other modes are not implemented
@@ -110,6 +119,10 @@
    */
   typedef std::map<CommandName, shared_ptr<Command>> CommandContainer;
   CommandContainer m_commands;
+
+  /** \brief commands in insertion order
+   */
+  std::vector<CommandContainer::const_iterator> m_commandOrder;
 };
 
 } // namespace nfdc
diff --git a/tools/nfdc/format-helpers.cpp b/tools/nfdc/format-helpers.cpp
index 3496104..942a9f1 100644
--- a/tools/nfdc/format-helpers.cpp
+++ b/tools/nfdc/format-helpers.cpp
@@ -88,6 +88,15 @@
 
 namespace text {
 
+std::ostream&
+operator<<(std::ostream& os, const Spaces& spaces)
+{
+  for (int i = 0; i < spaces.nSpaces; ++i) {
+    os << ' ';
+  }
+  return os;
+}
+
 Separator::Separator(const std::string& first, const std::string& subsequent)
   : m_first(first)
   , m_subsequent(subsequent)
diff --git a/tools/nfdc/format-helpers.hpp b/tools/nfdc/format-helpers.hpp
index 6629409..4c7badd 100644
--- a/tools/nfdc/format-helpers.hpp
+++ b/tools/nfdc/format-helpers.hpp
@@ -67,6 +67,16 @@
 
 namespace text {
 
+/** \brief print a number of whitespaces
+ */
+struct Spaces
+{
+  int nSpaces; ///< number of spaces; print nothing if negative
+};
+
+std::ostream&
+operator<<(std::ostream& os, const Spaces& spaces);
+
 /** \brief print different string on first and subsequent usage
  *
  *  \code
diff --git a/tools/nfdc/help.cpp b/tools/nfdc/help.cpp
new file mode 100644
index 0000000..6088607
--- /dev/null
+++ b/tools/nfdc/help.cpp
@@ -0,0 +1,104 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2016,  Regents of the University of California,
+ *                           Arizona Board of Regents,
+ *                           Colorado State University,
+ *                           University Pierre & Marie Curie, Sorbonne University,
+ *                           Washington University in St. Louis,
+ *                           Beijing Institute of Technology,
+ *                           The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "help.hpp"
+#include "format-helpers.hpp"
+#include <ndn-cxx/util/logger.hpp>
+#include <unistd.h>
+
+namespace nfd {
+namespace tools {
+namespace nfdc {
+
+NDN_LOG_INIT(nfdc.Help);
+
+const int LIST_COMMAND_NAME_COLUMN_WIDTH = 16;
+
+void
+helpList(std::ostream& os, const CommandParser& parser, ParseMode mode, const std::string& noun)
+{
+  os << "nfdc [-h] [-V] <command> [<args>]\n\n";
+  if (noun.empty()) {
+    os << "All subcommands:\n";
+  }
+  else {
+    os << "Subcommands starting with " << noun << ":\n";
+  }
+
+  std::vector<const CommandDefinition*> commands = parser.listCommands(noun, mode);
+  if (commands.empty()) {
+    os << "  (none)\n";
+    return;
+  }
+
+  for (auto def : commands) {
+    os << "  " << def->getNoun() << ' ' << def->getVerb() << ' '
+       << text::Spaces{static_cast<int>(LIST_COMMAND_NAME_COLUMN_WIDTH -
+                       def->getNoun().size() - def->getVerb().size() - 2)}
+       << def->getTitle() << '\n';
+  }
+
+  os << "\nSee 'nfdc help <command>' to read about a specific subcommand.\n";
+}
+
+static int
+helpSingle(const std::string& noun, const std::string& verb)
+{
+  std::string manpage = "nfdc-" + noun;
+
+  execlp("man", "man", manpage.data(), nullptr);
+  NDN_LOG_FATAL("Error opening man page for " << manpage);
+  return 1;
+}
+
+int
+help(ExecuteContext& ctx, const CommandParser& parser, std::ostream& os)
+{
+  std::string noun = ctx.args.get<std::string>("noun", "");
+  std::string verb = ctx.args.get<std::string>("verb", "");
+
+  if (noun.empty()) {
+    helpList(os, parser, ParseMode::ONE_SHOT, noun);
+    return 0;
+  }
+  else {
+    return helpSingle(noun, verb);
+  }
+}
+
+void
+registerHelpCommand(CommandParser& parser)
+{
+  CommandDefinition defHelp("help", "");
+  defHelp
+    .setTitle("display help information")
+    .addArg("noun", ArgValueType::STRING, Required::NO, Positional::YES)
+    .addArg("verb", ArgValueType::STRING, Required::NO, Positional::YES);
+  parser.addCommand(defHelp, bind(&help, _1, cref(parser), ref(std::cout)));
+}
+
+} // namespace nfdc
+} // namespace tools
+} // namespace nfd
diff --git a/tools/nfdc/help.hpp b/tools/nfdc/help.hpp
new file mode 100644
index 0000000..4fd2dc5
--- /dev/null
+++ b/tools/nfdc/help.hpp
@@ -0,0 +1,53 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2016,  Regents of the University of California,
+ *                           Arizona Board of Regents,
+ *                           Colorado State University,
+ *                           University Pierre & Marie Curie, Sorbonne University,
+ *                           Washington University in St. Louis,
+ *                           Beijing Institute of Technology,
+ *                           The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NFD_TOOLS_NFDC_HELP_HPP
+#define NFD_TOOLS_NFDC_HELP_HPP
+
+#include "command-parser.hpp"
+
+namespace nfd {
+namespace tools {
+namespace nfdc {
+
+void
+helpList(std::ostream& os, const CommandParser& parser,
+         ParseMode mode = ParseMode::ONE_SHOT, const std::string& noun = "");
+
+/** \brief the 'help' command
+ */
+int
+help(ExecuteContext& ctx, const CommandParser& parser, std::ostream& os);
+
+/** \brief registers 'help' command
+ */
+void
+registerHelpCommand(CommandParser& parser);
+
+} // namespace nfdc
+} // namespace tools
+} // namespace nfd
+
+#endif // NFD_TOOLS_NFDC_HELP_HPP
diff --git a/tools/nfdc/main.cpp b/tools/nfdc/main.cpp
index bcd9da3..da403c8 100644
--- a/tools/nfdc/main.cpp
+++ b/tools/nfdc/main.cpp
@@ -24,7 +24,7 @@
  */
 
 #include "available-commands.hpp"
-#include "legacy-nfdc.hpp"
+#include "help.hpp"
 #include "core/version.hpp"
 
 namespace nfd {
@@ -36,8 +36,11 @@
 {
   std::vector<std::string> args(argv + 1, argv + argc);
 
+  CommandParser parser;
+  registerCommands(parser);
+
   if (args.empty() || args[0] == "-h") {
-    legacyNfdcUsage();
+    helpList(std::cout, parser);
     return 0;
   }
 
@@ -46,8 +49,6 @@
     return 0;
   }
 
-  CommandParser parser;
-  registerCommands(parser);
   std::string noun, verb;
   CommandArguments ca;
   ExecuteCommand execute;
diff --git a/wscript b/wscript
index f3052b9..866c437 100644
--- a/wscript
+++ b/wscript
@@ -249,6 +249,14 @@
             source=bld.path.ant_glob('docs/manpages/**/*.rst'),
             install_path="${MANDIR}/",
             VERSION=VERSION)
+        bld.symlink_as('${MANDIR}/man1/nfdc-channel.1', 'nfdc-face.1')
+        bld.symlink_as('${MANDIR}/man1/nfdc-create.1', 'nfdc-face.1')
+        bld.symlink_as('${MANDIR}/man1/nfdc-destroy.1', 'nfdc-face.1')
+        bld.symlink_as('${MANDIR}/man1/nfdc-fib.1', 'nfdc-route.1')
+        bld.symlink_as('${MANDIR}/man1/nfdc-register.1', 'nfdc-route.1')
+        bld.symlink_as('${MANDIR}/man1/nfdc-unregister.1', 'nfdc-route.1')
+        bld.symlink_as('${MANDIR}/man1/nfdc-set-strategy.1', 'nfdc-strategy.1')
+        bld.symlink_as('${MANDIR}/man1/nfdc-unset-strategy.1', 'nfdc-strategy.1')
 
     bld.install_files("${SYSCONFDIR}/ndn", "autoconfig.conf.sample")