Test to see if auto_props and label_mapper files are readable.
[vss2svn.git] / ssphys / SSPhys / ssphys.cpp
blob10ae4d3b625f577d62f18b81538b0f90f59730d8
1 // ssphys.cpp : Defines the entry point for the console application.
2 //
4 #include "StdAfx.h"
5 #include "../version.h"
7 //#include "SSTests.h"
8 #include "CommandLine.h"
9 #include "Command.h"
10 #include "GlobalOptions.h"
11 #include "Formatter.h"
12 #include "CommandFactory.h"
14 #include <boost/program_options/detail/cmdline.hpp>
15 using namespace boost::program_options::detail;
16 namespace pod = boost::program_options::detail;
18 //---------------------------------------------------------------------------
19 void Info (const char* message)
21 std::cerr << "INFO: " << message << std::endl;
24 void Notice (const char* message)
26 std::cerr << "NOTICE: " << message << std::endl;
29 void Warning (const char* message)
31 std::cerr << "WARNING: " << message << std::endl;
34 void Error (const char* message)
36 std::cerr << "ERROR: " << message << std::endl;
39 //---------------------------------------------------------------------------
40 po::options_description GetGlobalOptions ()
42 po::options_description descr ("global options");
43 descr.add_options()
44 ("help,h", "produce help message")
45 ("version,v", "print version string");
47 return descr;
51 //---------------------------------------------------------------------------
52 void PrintUsage ()
54 std::cout << " ssphys [OPTIONS]" << std::endl;
55 std::cout << "or ssphys command [OPTIONS] <file>" << std::endl;
56 std::cout << std::endl;
57 std::cout << GetGlobalOptions () << std::endl;
59 CCommandFactory factory;
60 factory.PrintUsage ();
63 //---------------------------------------------------------------------------
64 void PrintVersion ()
66 std::cout << "ssphys " << STRFILEVER << std::endl;
69 bool HandleGlobalOptions (po::variables_map vm)
71 if (vm.count("help")) {
72 PrintUsage();
73 return true;
75 if (vm.count("version")) {
76 PrintVersion();
77 return true;
79 return false;
82 //---------------------------------------------------------------------------
83 int main(int argc, char* argv[])
85 #if 0
86 // TODO: set this to the correct locale
87 tzset ();
88 setlocale (LC_TIME, "German");
89 #endif
91 int ret = -1;
92 try
94 // first argument is command, the rest are the arguments to the command
95 // if no command given
96 if (argc < 2)
97 throw missing_command ();
99 // if no command argument check for global options
100 if (argv[1] && strlen (argv[1]) >= 1 && argv[1][0]=='-')
102 po::options_description descr = GetGlobalOptions ();
104 po::variables_map vm;
105 po::parsed_options opts = po::command_line_parser(argc, argv)
106 .options(descr)
107 .run();
108 po::store (opts, vm);
109 po::notify(vm);
111 if (HandleGlobalOptions (vm))
112 return 0;
115 // otherwise get the command and execute it.
116 std::string command (argv[1]);
117 std::vector<std::string> arguments (argv + 2, argv+argc);
119 CCommandFactory factory;
120 std::auto_ptr <CCommand> pCommand (factory.MakeCommand (command));
121 if (pCommand.get ())
122 ret = pCommand->Execute(arguments);
124 catch (std::exception& ex)
126 std::cerr << argv[0] << ": " << ex.what() << std::endl;
127 std::cerr << "Try `" << argv[0] << " --help` for more information" << std::endl;
128 return -1;
131 return ret;