1 // ssphys.cpp : Defines the entry point for the console application.
5 #include "../version.h"
8 #include "CommandLine.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");
44 ("help,h", "produce help message")
45 ("version,v", "print version string");
51 //---------------------------------------------------------------------------
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 //---------------------------------------------------------------------------
66 std::cout
<< "ssphys " << STRFILEVER
<< std::endl
;
69 bool HandleGlobalOptions (po::variables_map vm
)
71 if (vm
.count("help")) {
75 if (vm
.count("version")) {
82 //---------------------------------------------------------------------------
83 int main(int argc
, char* argv
[])
86 // TODO: set this to the correct locale
88 setlocale (LC_TIME
, "German");
94 // first argument is command, the rest are the arguments to the command
95 // if no command given
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
)
108 po::store (opts
, vm
);
111 if (HandleGlobalOptions (vm
))
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
));
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
;