tools: implement 'nfdc cs erase' command

refs #4318

Change-Id: If4dc401a3efff44a5bf4b3074d21797f8384cf9f
diff --git a/tools/nfdc/cs-module.cpp b/tools/nfdc/cs-module.cpp
index 6a3b0b5..fafd095 100644
--- a/tools/nfdc/cs-module.cpp
+++ b/tools/nfdc/cs-module.cpp
@@ -42,6 +42,13 @@
     .addArg("admit", ArgValueType::BOOLEAN, Required::NO, Positional::NO)
     .addArg("serve", ArgValueType::BOOLEAN, Required::NO, Positional::NO);
   parser.addCommand(defCsConfig, &CsModule::config);
+
+  CommandDefinition defCsErase("cs", "erase");
+  defCsErase
+    .setTitle("erase cached Data")
+    .addArg("prefix", ArgValueType::NAME, Required::YES, Positional::YES)
+    .addArg("count", ArgValueType::UNSIGNED, Required::NO, Positional::NO);
+  parser.addCommand(defCsErase, &CsModule::erase);
 }
 
 void
@@ -80,6 +87,34 @@
 }
 
 void
+CsModule::erase(ExecuteContext& ctx)
+{
+  auto prefix = ctx.args.get<Name>("prefix");
+  auto count = ctx.args.getOptional<uint64_t>("count");
+
+  ControlParameters params;
+  params.setName(prefix);
+  if (count) {
+    params.setCount(*count);
+  }
+
+  ctx.controller.start<ndn::nfd::CsEraseCommand>(
+    params,
+    [&] (const ControlParameters& resp) {
+      text::ItemAttributes ia;
+      ctx.out << "cs-erased "
+              << ia("prefix") << resp.getName()
+              << ia("count") << resp.getCount()
+              << ia("has-more") << text::YesNo{resp.hasCapacity()}
+              << '\n';
+    },
+    ctx.makeCommandFailureHandler("erasing cached Data"),
+    ctx.makeCommandOptions());
+
+  ctx.face.processEvents();
+}
+
+void
 CsModule::fetchStatus(Controller& controller,
                       const std::function<void()>& onSuccess,
                       const Controller::DatasetFailCallback& onFailure,