tools: nfdc strategy set/unset commands

nfdc set-strategy and nfdc unset-strategy are deprecated.

refs #3865

Change-Id: I934cbfcd567ac7ee33381ae4baf00b668977a0aa
diff --git a/tools/nfdc/strategy-choice-module.cpp b/tools/nfdc/strategy-choice-module.cpp
index e5fe584..9e0031f 100644
--- a/tools/nfdc/strategy-choice-module.cpp
+++ b/tools/nfdc/strategy-choice-module.cpp
@@ -43,6 +43,19 @@
     .setTitle("show strategy choice of an entry")
     .addArg("prefix", ArgValueType::NAME, Required::YES, Positional::YES);
   parser.addCommand(defStrategyShow, &StrategyChoiceModule::show);
+
+  CommandDefinition defStrategySet("strategy", "set");
+  defStrategySet
+    .setTitle("set strategy choice for a name prefix")
+    .addArg("prefix", ArgValueType::NAME, Required::YES, Positional::YES)
+    .addArg("strategy", ArgValueType::NAME, Required::YES, Positional::YES);
+  parser.addCommand(defStrategySet, &StrategyChoiceModule::set);
+
+  CommandDefinition defStrategyUnset("strategy", "unset");
+  defStrategyUnset
+    .setTitle("clear strategy choice at a name prefix")
+    .addArg("prefix", ArgValueType::NAME, Required::YES, Positional::YES);
+  parser.addCommand(defStrategyUnset, &StrategyChoiceModule::unset);
 }
 
 void
@@ -84,6 +97,58 @@
 }
 
 void
+StrategyChoiceModule::set(ExecuteContext& ctx)
+{
+  auto prefix = ctx.args.get<Name>("prefix");
+  auto strategy = ctx.args.get<Name>("strategy");
+
+  ctx.controller.start<ndn::nfd::StrategyChoiceSetCommand>(
+    ControlParameters().setName(prefix).setStrategy(strategy),
+    [&] (const ControlParameters& resp) {
+      ctx.out << "strategy-set ";
+      text::ItemAttributes ia;
+      ctx.out << ia("prefix") << resp.getName()
+              << ia("strategy") << resp.getStrategy() << '\n';
+    },
+    [&] (const ControlResponse& resp) {
+      if (resp.getCode() == 404) {
+        ctx.exitCode = 7;
+        ctx.err << "Unknown strategy: " << strategy << '\n';
+        ///\todo #3887 list available strategies
+        return;
+      }
+      ctx.makeCommandFailureHandler("setting strategy")(resp); // invoke general error handler
+    },
+    ctx.makeCommandOptions());
+
+  ctx.face.processEvents();
+}
+
+void
+StrategyChoiceModule::unset(ExecuteContext& ctx)
+{
+  auto prefix = ctx.args.get<Name>("prefix");
+
+  if (prefix.empty()) {
+    ctx.exitCode = 2;
+    ctx.err << "Unsetting default strategy is prohibited\n";
+    return;
+  }
+
+  ctx.controller.start<ndn::nfd::StrategyChoiceUnsetCommand>(
+    ControlParameters().setName(prefix),
+    [&] (const ControlParameters& resp) {
+      ctx.out << "strategy-unset ";
+      text::ItemAttributes ia;
+      ctx.out << ia("prefix") << resp.getName() << '\n';
+    },
+    ctx.makeCommandFailureHandler("unsetting strategy"),
+    ctx.makeCommandOptions());
+
+  ctx.face.processEvents();
+}
+
+void
 StrategyChoiceModule::fetchStatus(Controller& controller,
                                   const function<void()>& onSuccess,
                                   const Controller::DatasetFailCallback& onFailure,