available-commands.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "available-commands.hpp"
27 #include "status-report.hpp"
28 #include "status-main.hpp"
29 #include "legacy-nfdc.hpp"
30 
31 namespace nfd {
32 namespace tools {
33 namespace nfdc {
34 
35 static int
37 {
38  ReportFormat fmt = ctx.args.get<ReportFormat>("format", ReportFormat::TEXT);
39  switch (fmt) {
40  case ReportFormat::XML:
41  return statusMain(std::vector<std::string>{"-x"}, ctx.face, ctx.keyChain);
42  case ReportFormat::TEXT:
43  return statusMain(std::vector<std::string>{}, ctx.face, ctx.keyChain);
44  }
45  BOOST_ASSERT(false);
46  return 1;
47 }
48 
49 static int
50 statusList(ExecuteContext& ctx, const std::string& option)
51 {
52  return statusMain(std::vector<std::string>{option}, ctx.face, ctx.keyChain);
53 }
54 
55 static int
57 {
58  auto args = ctx.args.get<std::vector<std::string>>("args");
59  return statusMain(args, ctx.face, ctx.keyChain);
60 }
61 
62 void
64 {
65  CommandDefinition defStatusReport("status", "report");
66  defStatusReport
68  parser.addCommand(defStatusReport, &statusReport);
69 
70  struct StatusCommandDefinition
71  {
72  std::string noun;
73  std::string verb;
74  std::string legacyOption;
75  };
76  const std::vector<StatusCommandDefinition> statusCommands{
77  {"status", "show", "-v"},
78  {"face", "list", "-f"},
79  {"channel", "list", "-c"},
80  {"strategy", "list", "-s"},
81  {"fib", "list", "-b"},
82  {"route", "list", "-r"}
83  };
84  for (const StatusCommandDefinition& scd : statusCommands) {
85  CommandDefinition def(scd.noun, scd.verb);
86  parser.addCommand(def, bind(&statusList, _1, scd.legacyOption));
87  }
88  parser.addAlias("status", "show", "list");
89 
90  CommandDefinition defLegacyNfdStatus("legacy-nfd-status", "");
91  defLegacyNfdStatus
93  parser.addCommand(defLegacyNfdStatus, &legacyNfdStatus);
94 
95  const std::vector<std::string> legacyNfdcSubcommands{
96  "register",
97  "unregister",
98  "create",
99  "destroy",
100  "set-strategy",
101  "unset-strategy",
102  "add-nexthop",
103  "remove-nexthop"
104  };
105  for (const std::string& subcommand : legacyNfdcSubcommands) {
106  CommandDefinition def(subcommand, "");
108  parser.addCommand(def, &legacyNfdcMain);
109  }
110 }
111 
112 } // namespace nfdc
113 } // namespace tools
114 } // namespace nfd
declares semantics of a command
context for command execution
static int statusList(ExecuteContext &ctx, const std::string &option)
static int legacyNfdStatus(ExecuteContext &ctx)
int statusMain(const std::vector< std::string > &args, Face &face, KeyChain &keyChain)
T get(const std::string &key, const T &defaultValue=T()) const
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
const CommandArguments & args
CommandDefinition & addArg(const std::string &name, ArgValueType valueType, Required isRequired=Required::NO, Positional allowPositional=Positional::NO, const std::string &metavar="")
declare an argument
int legacyNfdcMain(ExecuteContext &ctx)
argument is required
CommandParser & addCommand(const CommandDefinition &def, const ExecuteCommand &execute, std::underlying_type< AvailableIn >::type modes=AVAILABLE_IN_ALL)
add an available command
static int statusReport(ExecuteContext &ctx)
argument is optional
void registerCommands(CommandParser &parser)
CommandParser & addAlias(const std::string &noun, const std::string &verb, const std::string &verb2)
add an alias "noun verb2" to existing command "noun verb"
report format 'xml' or 'text'