tools: add exit code and streams to nfdc::ExecuteContext

Moving exit code to the context allows error handling routines to
rely only on the context.

Moving stdout and stderr streams to the context allows mocking in
unit tests, and allows sending output to a buffer for pre-processing
when we implement interactive mode.

refs #3864

Change-Id: Ibf59c12405d0eaca0597835cb2e30125b7f70adb
diff --git a/tools/nfdc/legacy-nfdc.cpp b/tools/nfdc/legacy-nfdc.cpp
index 467789e..86d9ad5 100644
--- a/tools/nfdc/legacy-nfdc.cpp
+++ b/tools/nfdc/legacy-nfdc.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+ * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -325,7 +325,7 @@
     << std::endl;
 }
 
-int
+void
 legacyNfdcMain(ExecuteContext& ctx)
 {
   LegacyNfdc p(ctx.face, ctx.keyChain);
@@ -357,7 +357,8 @@
   catch (const po::error& e) {
     std::cerr << e.what() << std::endl;
     legacyNfdcUsage();
-    return 2;
+    ctx.exitCode = 2;
+    return;
   }
 
   if (wantUnsetChildInherit) {
@@ -378,17 +379,18 @@
       [] (const std::string& s) { return s.empty() || s[0] == '-'; })) {
     // unrecognized -option
     legacyNfdcUsage();
-    return 2;
+    ctx.exitCode = 2;
+    return;
   }
   p.m_commandLineArguments = unparsed;
 
   bool isOk = p.dispatch(subcommand);
   if (!isOk) {
     legacyNfdcUsage();
-    return 2;
+    ctx.exitCode = 2;
+    return;
   }
   ctx.face.processEvents();
-  return 0;
 }
 
 } // namespace nfdc