diff options
author | randomdan <randomdan@localhost> | 2013-12-31 10:49:12 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2013-12-31 10:49:12 +0000 |
commit | f35665803d086b08befb04c3d5f9a95986506d54 (patch) | |
tree | 35ca98e9b141796e511546b113b2ca5d6a416c4b | |
parent | Add support for writing a pidfile, drop user privs and forking into a daemon (diff) | |
download | project2-f35665803d086b08befb04c3d5f9a95986506d54.tar.bz2 project2-f35665803d086b08befb04c3d5f9a95986506d54.tar.xz project2-f35665803d086b08befb04c3d5f9a95986506d54.zip |
Tidy up the code for adding a help option
-rw-r--r-- | project2/basics/options/showHelp.cpp | 7 | ||||
-rw-r--r-- | project2/basics/options/showHelp.h | 7 | ||||
-rw-r--r-- | project2/cgi/testCgi.cpp | 2 | ||||
-rw-r--r-- | project2/console/consoleAppEngine.cpp | 3 | ||||
-rw-r--r-- | project2/daemon/p2daemonAppEngine.cpp | 2 |
5 files changed, 14 insertions, 7 deletions
diff --git a/project2/basics/options/showHelp.cpp b/project2/basics/options/showHelp.cpp index feabd45..acdede6 100644 --- a/project2/basics/options/showHelp.cpp +++ b/project2/basics/options/showHelp.cpp @@ -2,6 +2,7 @@ #include <options.h> #include <boost/bind.hpp> #include <boost/foreach.hpp> +#include <options/flagSet.h> void ShowHelpComponent::onConfigLoad() { @@ -20,6 +21,12 @@ void ShowHelpComponent::outputOptions(const Options * options) const } } +Options::TargetPtr +ShowHelpComponent::Option() +{ + return new OptionFlagSet(&showHelp); +} + bool ShowHelpComponent::showHelp; DECLARE_COMPONENT("ShowHelpComponent", ShowHelpComponent); diff --git a/project2/basics/options/showHelp.h b/project2/basics/options/showHelp.h index e1b95ef..21eec95 100644 --- a/project2/basics/options/showHelp.h +++ b/project2/basics/options/showHelp.h @@ -2,16 +2,15 @@ #define SHOWHELP_H #include <componentLoader.h> - -class Options; +#include <options.h> class ShowHelpComponent : public ComponentLoader { public: void onConfigLoad(); + static Options::TargetPtr Option(); + private: void outputOptions(const Options * options) const; - - public: static bool showHelp; }; diff --git a/project2/cgi/testCgi.cpp b/project2/cgi/testCgi.cpp index e842958..58b823f 100644 --- a/project2/cgi/testCgi.cpp +++ b/project2/cgi/testCgi.cpp @@ -7,6 +7,7 @@ #include "../cli/claOptions.h" #include "cgiRequestContext.h" #include "cgiAppEngine.h" +#include <options/showHelp.h> #define TESTOPT(name, def, desc) \ (name, Options::value(optStore().insert(OptStore::value_type(name, StrPtr(new std::string()))).first->second.get(), def), desc) @@ -120,6 +121,7 @@ TESTOPT("HTTPS", "No", "HTTPS?") TESTOPT("HTTP_IF_MODIFIED_SINCE", "", "Client cached copy timestamp") ("urlListFile", Options::value(&urlListFile, ""), "Load URL list from this file") ("runCount", Options::value(&runCount, 1), "Repeat run this many times") +("help", ShowHelpComponent::Option(), "Print usage and exit")("h") END_OPTIONS(TestInput); int diff --git a/project2/console/consoleAppEngine.cpp b/project2/console/consoleAppEngine.cpp index 8aa4fc0..d2d70c6 100644 --- a/project2/console/consoleAppEngine.cpp +++ b/project2/console/consoleAppEngine.cpp @@ -8,7 +8,6 @@ #include "viewHost.h" #include "taskHost.h" #include "scriptLoader.h" -#include <options/flagSet.h> #include <options/showHelp.h> #include <boost/foreach.hpp> #include <boost/bind.hpp> @@ -19,7 +18,7 @@ StaticMessageException(InvalidScriptName, "Script name should be group/name"); SimpleMessageException(UnknownPlatformAlias); DECLARE_OPTIONS(ConsoleApplicationEngine, "Console options") -("help", new OptionFlagSet(&ShowHelpComponent::showHelp), +("help", ShowHelpComponent::Option(), "Print usage and exit")("h") ("console.platform", Options::value(&reqPlatform), "Platform")("p") diff --git a/project2/daemon/p2daemonAppEngine.cpp b/project2/daemon/p2daemonAppEngine.cpp index 908b2b7..b48b75b 100644 --- a/project2/daemon/p2daemonAppEngine.cpp +++ b/project2/daemon/p2daemonAppEngine.cpp @@ -23,7 +23,7 @@ SimpleMessageException(NoSuchUser); SimpleMessageException(NoSuchGroup); DECLARE_OPTIONS(DaemonAppEngine, "Project2 Daemon options") -("help", new OptionFlagSet(&ShowHelpComponent::showHelp), +("help", ShowHelpComponent::Option(), "Print usage and exit")("h") ("daemon.type", Options::value(&daemonType), "The core daemon module to run") ("daemon.platform", Options::value(&reqPlatform), "Platform") |