ndnpeek: add --link-file option

Change-Id: Idbf283a5ae23be76f9eb2752906c8aec21b2fede
Refs: #3112
diff --git a/manpages/ndnpeek.rst b/manpages/ndnpeek.rst
index 3735337..fe7b41a 100644
--- a/manpages/ndnpeek.rst
+++ b/manpages/ndnpeek.rst
@@ -51,6 +51,9 @@
 ``-V, --version``
   Print version and exit.
 
+``--link-file [file]``
+  Read Link object from ``file`` and add it to the expressed Interest.
+
 Exit Codes
 ----------
 
diff --git a/tools/peek/ndn-peek.cpp b/tools/peek/ndn-peek.cpp
index 2f3bef5..5c9df4d 100644
--- a/tools/peek/ndn-peek.cpp
+++ b/tools/peek/ndn-peek.cpp
@@ -121,6 +121,14 @@
   }
 
   void
+  setLink(const std::string& file)
+  {
+    m_link = io::load<Link>(file);
+    if (m_link == nullptr)
+      throw std::runtime_error(file + " is either nonreadable or nonparseable");
+  }
+
+  void
   setPrefixName(const std::string& prefixName)
   {
     m_prefixName = prefixName;
@@ -155,6 +163,9 @@
     else
       interestPacket.setInterestLifetime(m_interestLifetime);
 
+    if (m_link != nullptr)
+      interestPacket.setLink(m_link->wireEncode());
+
     if (isVerbose) {
       std::cerr << "INTEREST: " << interestPacket << std::endl;
     }
@@ -229,6 +240,7 @@
   time::milliseconds m_timeout;
   std::string m_prefixName;
   time::steady_clock::TimePoint m_expressInterestTime;
+  shared_ptr<Link> m_link;
   bool m_didReceiveData;
   Face m_face;
 };
@@ -260,6 +272,8 @@
         "set timeout (in milliseconds)")
     ("verbose,v", po::bool_switch(&program.isVerbose),
         "turn on verbose output")
+    ("link-file", po::value<std::string>()->notifier(bind(&NdnPeek::setLink, &program, _1)),
+        "set Link from a file")
   ;
 
   po::options_description hiddenOptDesc("Hidden options");