Erik Hofman:
I've modified the code to display a brief help message instead of the whole bunch of options. To get the complete message -v or --verbose has to be added to the command line.
This commit is contained in:
parent
df6989a37a
commit
b21333d4f8
2 changed files with 36 additions and 16 deletions
src/Main
|
@ -68,7 +68,8 @@ enum
|
||||||
{
|
{
|
||||||
FG_OPTIONS_OK = 0,
|
FG_OPTIONS_OK = 0,
|
||||||
FG_OPTIONS_HELP = 1,
|
FG_OPTIONS_HELP = 1,
|
||||||
FG_OPTIONS_ERROR = 2
|
FG_OPTIONS_ERROR = 2,
|
||||||
|
FG_OPTIONS_VERBOSE_HELP = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
static double
|
static double
|
||||||
|
@ -594,6 +595,9 @@ parse_option (const string& arg)
|
||||||
if ( (arg == "--help") || (arg == "-h") ) {
|
if ( (arg == "--help") || (arg == "-h") ) {
|
||||||
// help/usage request
|
// help/usage request
|
||||||
return(FG_OPTIONS_HELP);
|
return(FG_OPTIONS_HELP);
|
||||||
|
} else if ( (arg == "--verbose") || (arg == "-v") ) {
|
||||||
|
// verbose help/usage request
|
||||||
|
return(FG_OPTIONS_VERBOSE_HELP);
|
||||||
} else if ( arg == "--disable-game-mode") {
|
} else if ( arg == "--disable-game-mode") {
|
||||||
fgSetBool("/sim/startup/game-mode", false);
|
fgSetBool("/sim/startup/game-mode", false);
|
||||||
} else if ( arg == "--enable-game-mode" ) {
|
} else if ( arg == "--enable-game-mode" ) {
|
||||||
|
@ -1061,6 +1065,8 @@ void
|
||||||
fgParseArgs (int argc, char **argv)
|
fgParseArgs (int argc, char **argv)
|
||||||
{
|
{
|
||||||
bool in_options = true;
|
bool in_options = true;
|
||||||
|
bool verbose = false;
|
||||||
|
bool help = false;
|
||||||
|
|
||||||
SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
|
SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
|
||||||
|
|
||||||
|
@ -1072,11 +1078,11 @@ fgParseArgs (int argc, char **argv)
|
||||||
in_options = false;
|
in_options = false;
|
||||||
} else {
|
} else {
|
||||||
int result = parse_option(arg);
|
int result = parse_option(arg);
|
||||||
if ( (result == FG_OPTIONS_HELP) ||
|
if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
|
||||||
(result == FG_OPTIONS_ERROR) ) {
|
help = true;
|
||||||
fgUsage();
|
|
||||||
exit(-1);
|
else if (result == FG_OPTIONS_VERBOSE_HELP)
|
||||||
}
|
verbose = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
in_options = false;
|
in_options = false;
|
||||||
|
@ -1086,6 +1092,11 @@ fgParseArgs (int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (help) {
|
||||||
|
fgUsage(verbose);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
|
SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1135,7 +1146,7 @@ fgParseOptions (const string& path) {
|
||||||
|
|
||||||
// Print usage message
|
// Print usage message
|
||||||
void
|
void
|
||||||
fgUsage ()
|
fgUsage (bool verbose)
|
||||||
{
|
{
|
||||||
SGPropertyNode options_root;
|
SGPropertyNode options_root;
|
||||||
SGPath opath( globals->get_fg_root() );
|
SGPath opath( globals->get_fg_root() );
|
||||||
|
@ -1168,11 +1179,7 @@ fgUsage ()
|
||||||
|
|
||||||
vector<SGPropertyNode_ptr>section = options->getChildren("section");
|
vector<SGPropertyNode_ptr>section = options->getChildren("section");
|
||||||
for (unsigned int j = 0; j < section.size(); j++) {
|
for (unsigned int j = 0; j < section.size(); j++) {
|
||||||
|
string msg = "";
|
||||||
SGPropertyNode *name = section[j]->getNode("name");
|
|
||||||
if (name) {
|
|
||||||
cout << endl << name->getStringValue() << ":" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
|
vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
|
||||||
for (unsigned int k = 0; k < option.size(); k++) {
|
for (unsigned int k = 0; k < option.size(); k++) {
|
||||||
|
@ -1181,8 +1188,9 @@ fgUsage ()
|
||||||
SGPropertyNode *short_name = option[k]->getNode("short");
|
SGPropertyNode *short_name = option[k]->getNode("short");
|
||||||
SGPropertyNode *key = option[k]->getNode("key");
|
SGPropertyNode *key = option[k]->getNode("key");
|
||||||
SGPropertyNode *arg = option[k]->getNode("arg");
|
SGPropertyNode *arg = option[k]->getNode("arg");
|
||||||
|
bool brief = option[k]->getNode("brief");
|
||||||
|
|
||||||
if (name) {
|
if ((brief || verbose) && name) {
|
||||||
string tmp = name->getStringValue();
|
string tmp = name->getStringValue();
|
||||||
|
|
||||||
if (key){
|
if (key){
|
||||||
|
@ -1204,8 +1212,8 @@ fgUsage ()
|
||||||
} else {
|
} else {
|
||||||
snprintf(cstr, 96, "\n --%s\n%32c", tmp.c_str(), ' ');
|
snprintf(cstr, 96, "\n --%s\n%32c", tmp.c_str(), ' ');
|
||||||
}
|
}
|
||||||
string msg = cstr;
|
|
||||||
|
|
||||||
|
msg += cstr;
|
||||||
SGPropertyNode *desc = option[k]->getNode("description");
|
SGPropertyNode *desc = option[k]->getNode("description");
|
||||||
if (desc) {
|
if (desc) {
|
||||||
msg += desc->getStringValue();
|
msg += desc->getStringValue();
|
||||||
|
@ -1218,9 +1226,21 @@ fgUsage ()
|
||||||
desc->getStringValue());
|
desc->getStringValue());
|
||||||
msg += cstr;
|
msg += cstr;
|
||||||
}
|
}
|
||||||
|
msg += '\n';
|
||||||
}
|
}
|
||||||
cout << msg << endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SGPropertyNode *name = section[j]->getNode("name");
|
||||||
|
if (!msg.empty() && name) {
|
||||||
|
cout << endl << name->getStringValue() << ":" << endl;
|
||||||
|
cout << msg;
|
||||||
|
msg.erase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !verbose ) {
|
||||||
|
cout << endl;
|
||||||
|
cout << "For a complete list of options use --help --verbose" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,6 @@ extern string fgScanForRoot (int argc, char ** argv);
|
||||||
extern string fgScanForRoot (const string &file_path);
|
extern string fgScanForRoot (const string &file_path);
|
||||||
extern void fgParseArgs (int argc, char ** argv);
|
extern void fgParseArgs (int argc, char ** argv);
|
||||||
extern void fgParseOptions (const string &file_path);
|
extern void fgParseOptions (const string &file_path);
|
||||||
extern void fgUsage ();
|
extern void fgUsage (bool verbose = false);
|
||||||
|
|
||||||
#endif /* _OPTIONS_HXX */
|
#endif /* _OPTIONS_HXX */
|
||||||
|
|
Loading…
Add table
Reference in a new issue