changeset 175:662af781a227

sample config file from command line
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 05 Nov 2012 12:31:02 +0100
parents 43471da12ab9
children 81f11fb357f2
files CMakeLists.txt NEWS OrthancServer/main.cpp
diffstat 3 files changed, 24 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Fri Oct 26 16:47:11 2012 +0200
+++ b/CMakeLists.txt	Mon Nov 05 12:31:02 2012 +0100
@@ -47,6 +47,7 @@
   EmbedResources(
     PREPARE_DATABASE OrthancServer/PrepareDatabase.sql
     ORTHANC_EXPLORER OrthancExplorer
+    CONFIGURATION_SAMPLE Resources/Configuration.json
     )
 else()
   add_definitions(
@@ -55,6 +56,7 @@
     )
   EmbedResources(
     PREPARE_DATABASE OrthancServer/PrepareDatabase.sql
+    CONFIGURATION_SAMPLE Resources/Configuration.json
     )
 endif()
 
--- a/NEWS	Fri Oct 26 16:47:11 2012 +0200
+++ b/NEWS	Mon Nov 05 12:31:02 2012 +0100
@@ -1,7 +1,7 @@
 Pending changes in the mainline
 ===============================
 
-None
+* Generate a sample configuration file from command line
 
 
 Version 0.2.3 (2012/10/26)
--- a/OrthancServer/main.cpp	Fri Oct 26 16:47:11 2012 +0200
+++ b/OrthancServer/main.cpp	Mon Nov 05 12:31:02 2012 +0100
@@ -32,7 +32,7 @@
 
 #include "OrthancRestApi.h"
 
-#include <stdio.h>
+#include <fstream>
 #include <glog/logging.h>
 #include <boost/algorithm/string/predicate.hpp>
 
@@ -106,19 +106,21 @@
 {
   std::cout 
     << "Usage: " << path << " [OPTION]... [CONFIGURATION]" << std::endl
-    << "Start Orthanc, a lightweight, RESTful DICOM server for healthcare and medical research." << std::endl
+    << "Orthanc, lightweight, RESTful DICOM server for healthcare and medical research." << std::endl
     << std::endl
-    << "If no configuration file is given on the command line, a set of default parameters " << std::endl
-    << "is used. Please refer to the Orthanc homepage for the full instructions about how to use Orthanc " << std::endl
+    << "If no configuration file is given on the command line, a set of default " << std::endl
+    << "parameters is used. Please refer to the Orthanc homepage for the full " << std::endl
+    << "instructions about how to use Orthanc " << std::endl
     << "<https://code.google.com/p/orthanc/wiki/OrthancCookbook>." << std::endl
     << std::endl
     << "Command-line options:" << std::endl
-    << "  --verbose\t\tbe verbose in logs" << std::endl
-    << "  --trace\t\thighest verbosity in logs (for debug)" << std::endl
     << "  --help\t\tdisplay this help and exit" << std::endl
-    << "  --version\t\toutput version information and exit" << std::endl
     << "  --logdir=[dir]\tdirectory where to store the log files" << std::endl
     << "\t\t\t(if not used, the logs are dumped to stderr)" << std::endl
+    << "  --config=[file]\tcreate a sample configuration file and exit" << std::endl
+    << "  --trace\t\thighest verbosity in logs (for debug)" << std::endl
+    << "  --verbose\t\tbe verbose in logs" << std::endl
+    << "  --version\t\toutput version information and exit" << std::endl
     << std::endl
     << "Exit status:" << std::endl
     << " 0  if OK," << std::endl
@@ -177,6 +179,18 @@
       FLAGS_logtostderr = false;
       FLAGS_log_dir = std::string(argv[i]).substr(9);
     }
+
+    if (boost::starts_with(argv[i], "--config="))
+    {
+      std::string configurationSample;
+      GetFileResource(configurationSample, EmbeddedResources::CONFIGURATION_SAMPLE);
+
+      std::string target = std::string(argv[i]).substr(9);
+      std::ofstream f(target.c_str());
+      f << configurationSample;
+      f.close();
+      return 0;
+    }
   }
 
   google::InitGoogleLogging("Orthanc");