Index: src/controller.cpp
===================================================================
--- src/controller.cpp	(revision 311137ba72b2a6d1e9387251b02ad24abd7810de)
+++ src/controller.cpp	(revision 9dcce34bb40a82c811dead7c3f0fad21f1fffb01)
@@ -306,4 +306,85 @@
 }
 
+struct ControllerOptions
+{
+  int parseHelp(boost::program_options::variables_map &vm, const boost::program_options::options_description &desc) {
+    if (vm.count("help")) {
+      std::cout << desc << "\n";
+      return 1;
+    }
+    return 0;
+  }
+  int parseVerbosity(boost::program_options::variables_map &vm) {
+    if (vm.count("verbosity")) {
+      LOG(0, "STATUS: Verbosity level was set to " << vm["verbosity"].as<size_t>() << ".");
+      setVerbosity(vm["verbosity"].as<size_t>());
+    } else {
+      LOG(0, "STATUS: Verbosity level was not set, defaulting to 5.");
+      setVerbosity(5);
+    }
+    return 0;
+  }
+
+  int parseServerPort(boost::program_options::variables_map &vm) {
+    if (vm.count("server")) {
+      server = vm["server"].as< std::string >();
+      serverport = server.substr(server.find_last_of(':')+1, std::string::npos);
+      server = server.substr(0, server.find_last_of(':'));
+      try {
+        boost::lexical_cast<size_t>(serverport);
+      } catch (boost::bad_lexical_cast &) {
+        ELOG(1, "Could not interpret " << serverport << " as server:port.");
+        return 255;
+      }
+      LOG(1, "INFO: Using " << server << ":" << serverport << " as server's address.");
+    } else {
+      ELOG(1, "Requiring server's address (host:port) to connect to.");
+      return 255;
+    }
+    return 0;
+  }
+
+  int parseCommand(boost::program_options::variables_map &vm, const std::vector<std::string> &Commands) {
+    if (!vm.count("command")) {
+      ELOG(1, "Controller requires one of the following commands: "+toString(Commands));
+      return 255;
+    }
+    command = vm["command"].as< std::string >();
+    return 0;
+  }
+
+  std::string command;
+  std::string server;
+  std::string serverport;
+
+};
+
+struct ControllerOptions_SystemCommandJob : public ControllerOptions
+{
+  int parseExecutable(boost::program_options::variables_map &vm) {
+    if ((command == "createjobs") || (command == "addjobs")) {
+      if (!vm.count("executable")) {
+        ELOG(1, "'"+command+"' requires two options: [executable] [jobcommand].");
+        return 255;
+      }
+      executable = vm["executable"].as< std::string >();
+    }
+    return 0;
+  }
+
+  int parseJobCommand(boost::program_options::variables_map &vm) {
+    if (command == "createjobs") {
+      if (!vm.count("jobcommand")) {
+        ELOG(1, "'"+command+"' requires two options: [executable] [jobcommand].");
+        return 255;
+      }
+      jobcommand = vm["jobcommand"].as< std::string >();
+    }
+    return 0;
+  }
+
+  std::string executable;
+  std::string jobcommand;
+};
 
 int main(int argc, char* argv[])
@@ -345,56 +426,23 @@
   boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
   boost::program_options::notify(vm);
-
-  if (vm.count("help")) {
-    std::cout << desc << "\n";
-    return 1;
-  }
-
-  if (vm.count("verbosity")) {
-    LOG(0, "STATUS: Verbosity level was set to " << vm["verbosity"].as<size_t>() << ".");
-    setVerbosity(vm["verbosity"].as<size_t>());
-  } else {
-    LOG(0, "STATUS: Verbosity level was not set, defaulting to 5.");
-    setVerbosity(5);
-  }
-
-  std::string server;
-  std::string serverport;
-  if (vm.count("server")) {
-    server = vm["server"].as< std::string >();
-    serverport = server.substr(server.find_last_of(':')+1, std::string::npos);
-    server = server.substr(0, server.find_last_of(':'));
-    try {
-      boost::lexical_cast<size_t>(serverport);
-    } catch (boost::bad_lexical_cast) {
-      ELOG(1, "Could not interpret " << serverport << " as server:port.");
-      return 255;
-    }
-    LOG(1, "INFO: Using " << server << ":" << serverport << " as server's address.");
-  } else {
-    ELOG(1, "Requiring server's address (host:port) to connect to.");
-    return 255;
-  }
-
-  if (!vm.count("command")) {
-    ELOG(1, "Controller requires one of the following commands: "+toString(Commands));
-    return 255;
-  }
-  const std::string command = vm["command"].as< std::string >();
-  const CommandIndices commandIndex = getCommandIndex(CommandsMap, command);
+  ControllerOptions_SystemCommandJob ControllerInfo;
+
+  ControllerInfo.parseHelp(vm, desc);
+
+  ControllerInfo.parseVerbosity(vm);
+
+  ControllerInfo.parseServerPort(vm);
+
+  ControllerInfo.parseCommand(vm, Commands);
+  const CommandIndices commandIndex = getCommandIndex(CommandsMap, ControllerInfo.command);
+
+  ControllerInfo.parseExecutable(vm);
+
+  ControllerInfo.parseJobCommand(vm);
 
   // check arguments
   switch(commandIndex) {
     case AddJobsIndex:
-      if (!vm.count("executable") && !vm.count("jobfiles")) {
-        ELOG(1, "'"+command+"' requires at least two options: [executable] [list of input files ...].");
-        return 255;
-      }
-      break;
     case CreateJobsIndex:
-      if (!vm.count("executable") && !vm.count("jobcommand")) {
-        ELOG(1, "'"+command+"' requires two options: [executable] [jobcommand].");
-        return 255;
-      }
       break;
     case CheckResultsIndex:
@@ -404,5 +452,5 @@
     case ReceiveMPQCIndex:
       if (!vm.count("fragment-path")) {
-        ELOG(1, "'"+command+"' require one option: [path to fragment files].");
+        ELOG(1, "'"+ControllerInfo.command+"' require one option: [path to fragment files].");
         return 255;
       }
@@ -414,5 +462,5 @@
     case UnknownCommandIndex:
     default:
-      ELOG(1, "Unrecognized command '"+toString(command)+"'.");
+      ELOG(1, "Unrecognized command '"+toString(ControllerInfo.command)+"'.");
       return 255;
       break;
@@ -429,8 +477,8 @@
     switch(commandIndex) {
       case AddJobsIndex:
-        controller.requestIds(server, serverport, vm["jobfiles"].as< std::vector<std::string> >().size());
+        controller.requestIds(ControllerInfo.server, ControllerInfo.serverport, vm["jobfiles"].as< std::vector<std::string> >().size());
         break;
       case CreateJobsIndex:
-        controller.requestIds(server, serverport, 1);
+        controller.requestIds(ControllerInfo.server, ControllerInfo.serverport, 1);
         break;
       case CheckResultsIndex:
@@ -446,5 +494,5 @@
       case UnknownCommandIndex:
       default:
-        ELOG(0, "Unrecognized command '"+toString(command)+"'.");
+        ELOG(0, "Unrecognized command '"+toString(ControllerInfo.command)+"'.");
         return 255;
         break;
@@ -474,5 +522,5 @@
         }
         controller.addJobs(jobs);
-        controller.sendJobs(server, serverport);
+        controller.sendJobs(ControllerInfo.server, ControllerInfo.serverport);
         break;
       }
@@ -481,27 +529,25 @@
         const JobId_t next_id = controller.getAvailableId();
         std::vector<FragmentJob::ptr> jobs;
-        const std::string executable = vm["executable"].as< std::string >();
-        const std::string jobcommand = vm["jobcommand"].as< std::string >();
-        createjobs(jobs, executable, jobcommand, next_id);
+        createjobs(jobs, ControllerInfo.executable, ControllerInfo.jobcommand, next_id);
         controller.addJobs(jobs);
-        controller.sendJobs(server, serverport);
+        controller.sendJobs(ControllerInfo.server, ControllerInfo.serverport);
         break;
       }
       case CheckResultsIndex:
-        controller.checkResults(server, serverport);
+        controller.checkResults(ControllerInfo.server, ControllerInfo.serverport);
         break;
       case ReceiveResultsIndex:
       case ReceiveMPQCIndex:
-        controller.receiveResults(server, serverport);
+        controller.receiveResults(ControllerInfo.server, ControllerInfo.serverport);
         break;
       case RemoveAllIndex:
-        controller.removeall(server, serverport);
+        controller.removeall(ControllerInfo.server, ControllerInfo.serverport);
         break;
       case ShutdownIndex:
-        controller.shutdown(server, serverport);
+        controller.shutdown(ControllerInfo.server, ControllerInfo.serverport);
         break;
       case UnknownCommandIndex:
       default:
-        ELOG(0, "Unrecognized command '"+toString(command)+"'.");
+        ELOG(0, "Unrecognized command '"+toString(ControllerInfo.command)+"'.");
         return 255;
         break;
@@ -549,5 +595,5 @@
       case UnknownCommandIndex:
       default:
-        ELOG(0, "Unrecognized command '"+toString(command)+"'.");
+        ELOG(0, "Unrecognized command '"+toString(ControllerInfo.command)+"'.");
         return 255;
         break;
