summaryrefslogtreecommitdiff
path: root/cpp/src/IcePatch2/Client.cpp
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2004-12-16 03:15:51 +0000
committerMichi Henning <michi@zeroc.com>2004-12-16 03:15:51 +0000
commitb5c3efca572afd6c9cadbc87e9f4c068d312d928 (patch)
treee34f481e7ed94f176fcbe266767fea241dc3c764 /cpp/src/IcePatch2/Client.cpp
parentremove now returns null if the key is not found (diff)
downloadice-b5c3efca572afd6c9cadbc87e9f4c068d312d928.tar.bz2
ice-b5c3efca572afd6c9cadbc87e9f4c068d312d928.tar.xz
ice-b5c3efca572afd6c9cadbc87e9f4c068d312d928.zip
Changed command line parsing to use IceUtil::Options.
Diffstat (limited to 'cpp/src/IcePatch2/Client.cpp')
-rw-r--r--cpp/src/IcePatch2/Client.cpp75
1 files changed, 41 insertions, 34 deletions
diff --git a/cpp/src/IcePatch2/Client.cpp b/cpp/src/IcePatch2/Client.cpp
index d36cdb6d8f0..8c9581061f2 100644
--- a/cpp/src/IcePatch2/Client.cpp
+++ b/cpp/src/IcePatch2/Client.cpp
@@ -7,6 +7,7 @@
//
// **********************************************************************
+#include <IceUtil/Options.h>
#include <Ice/Application.h>
#include <IcePatch2/Util.h>
#include <IcePatch2/ClientUtil.h>
@@ -214,41 +215,47 @@ Client::run(int argc, char* argv[])
{
PropertiesPtr properties = communicator()->getProperties();
- for(int i = 1; i < argc; ++i)
+ IceUtil::Options opts;
+ opts.addOpt("h", "help");
+ opts.addOpt("v", "version");
+ opts.addOpt("t", "thorough");
+
+ vector<string> args;
+ try
{
- if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
- {
- usage(argv[0]);
- return EXIT_FAILURE;
- }
- else if(strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0)
- {
- cout << ICE_STRING_VERSION << endl;
- return EXIT_FAILURE;
- }
- else if(strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--thorough") == 0)
- {
- properties->setProperty("IcePatch2.Thorough", "1");
- }
- else if(argv[i][0] == '-')
- {
- cerr << argv[0] << ": unknown option `" << argv[i] << "'" << endl;
- usage(argv[0]);
- return EXIT_FAILURE;
- }
- else
- {
- if(properties->getProperty("IcePatch2.Directory").empty())
- {
- properties->setProperty("IcePatch2.Directory", argv[i]);
- }
- else
- {
- cerr << argv[0] << ": too many arguments" << endl;
- usage(argv[0]);
- return EXIT_FAILURE;
- }
- }
+ args = opts.parse(argc, argv);
+ }
+ catch(const IceUtil::Options::BadOpt& e)
+ {
+ cerr << e.reason << endl;
+ usage(argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ if(opts.isSet("h") || opts.isSet("help"))
+ {
+ usage(argv[0]);
+ return EXIT_SUCCESS;
+ }
+ if(opts.isSet("v") || opts.isSet("version"))
+ {
+ cout << ICE_STRING_VERSION << endl;
+ return EXIT_SUCCESS;
+ }
+ if(opts.isSet("t") || opts.isSet("thorough"))
+ {
+ properties->setProperty("IcePatch2.Thorough", "1");
+ }
+
+ if(args.size() > 1)
+ {
+ cerr << argv[0] << ": too many arguments" << endl;
+ usage(argv[0]);
+ return EXIT_FAILURE;
+ }
+ if(args.size() == 1)
+ {
+ properties->setProperty("IcePatch2.Directory", args[0]);
}
bool aborted = false;