aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Bouclet2018-02-04 12:57:21 +0100
committerBastien Bouclet2018-04-22 08:23:58 +0200
commit818117bda25c0cf6336b4fa8ae0d0bf0ce5e30a1 (patch)
tree98605f6d1950f81582334242a3d7a0b49ee9948a
parenta992dcc91a5574bad055c38ee89f4c284bae5c27 (diff)
downloadscummvm-rg350-818117bda25c0cf6336b4fa8ae0d0bf0ce5e30a1.tar.gz
scummvm-rg350-818117bda25c0cf6336b4fa8ae0d0bf0ce5e30a1.tar.bz2
scummvm-rg350-818117bda25c0cf6336b4fa8ae0d0bf0ce5e30a1.zip
BASE: Allow options to come after command on the command line
-rw-r--r--README8
-rw-r--r--base/commandLine.cpp30
2 files changed, 23 insertions, 15 deletions
diff --git a/README b/README
index beddb22b1c..58a3dac6e0 100644
--- a/README
+++ b/README
@@ -1467,15 +1467,15 @@ arguments -- see the next section.
-a, --add Add all games from current or specified directory.
If --game=ID is passed only the game with id ID is
added. See also --detect.
- Use --path=PATH before -a, --add to specify a directory.
+ Use --path=PATH to specify a directory.
--detect Display a list of games with their ID from current or
specified directory without adding it to the config.
- Use --path=PATH before --detect to specify a directory.
+ Use --path=PATH to specify a directory.
--game=ID In combination with --add or --detect only adds or attempts to
detect the game with id ID.
--auto-detect Display a list of games from current or specified directory
- and start the first one. Use --path=PATH before --auto-detect
- to specify a directory.
+ and start the first one. Use --path=PATH to specify
+ a directory.
--recursive In combination with --add or --detect recurse down all
subdirectories
--console Enable the console window (default: enabled) (Windows only)
diff --git a/base/commandLine.cpp b/base/commandLine.cpp
index bd8b9d07ac..f9090a864d 100644
--- a/base/commandLine.cpp
+++ b/base/commandLine.cpp
@@ -71,15 +71,14 @@ static const char HELP_STRING[] =
" --list-saves=TARGET Display a list of saved games for the game (TARGET) specified\n"
" -a, --add Add all games from current or specified directory.\n"
" If --game=ID is passed only the game with id ID is added. See also --detect\n"
- " Use --path=PATH before -a, --add to specify a directory.\n"
+ " Use --path=PATH to specify a directory.\n"
" --detect Display a list of games with their ID from current or\n"
" specified directory without adding it to the config.\n"
- " Use --path=PATH before --detect to specify a directory.\n"
+ " Use --path=PATH to specify a directory.\n"
" --game=ID In combination with --add or --detect only adds or attempts to\n"
" detect the game with id ID.\n"
" --auto-detect Display a list of games from current or specified directory\n"
- " and start the first one. Use --path=PATH before --auto-detect\n"
- " to specify a directory.\n"
+ " and start the first one. Use --path=PATH to specify a directory.\n"
" --recursive In combination with --add or --detect recurse down all subdirectories\n"
#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
" --console Enable the console window (default:enabled)\n"
@@ -196,6 +195,11 @@ static void usage(const char *s, ...) {
exit(1);
}
+static void ensureFirstCommand(const Common::String &existingCommand, const char *newCommand) {
+ if (!existingCommand.empty())
+ usage("--%s: Cannot accept more than one command (already found --%s).", newCommand, existingCommand.c_str());
+}
+
#endif // DISABLE_COMMAND_LINE
@@ -355,7 +359,8 @@ void registerDefaults() {
if (isLongCmd) \
s += sizeof(longCmd) - 1; \
if (*s != '\0') goto unknownOption; \
- return longCmd;
+ ensureFirstCommand(command, longCmd); \
+ command = longCmd;
#define DO_LONG_OPTION_OPT(longCmd, d) DO_OPTION_OPT(0, longCmd, d)
@@ -371,14 +376,16 @@ void registerDefaults() {
// End an option handler
#define END_COMMAND \
+ continue; \
}
Common::String parseCommandLine(Common::StringMap &settings, int argc, const char * const *argv) {
const char *s, *s2;
+ Common::String command;
if (!argv)
- return Common::String();
+ return command;
// argv[0] contains the name of the executable.
if (argv[0]) {
@@ -452,10 +459,11 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, const cha
#endif
DO_LONG_OPTION("list-saves")
- // FIXME: Need to document this.
// TODO: Make the argument optional. If no argument is given, list all saved games
// for all configured targets.
- return "list-saves";
+ // TODO: Consider breaking the command line interface to pass the argument via the --game option
+ ensureFirstCommand(command, "list-saves");
+ command = "list-saves";
END_OPTION
DO_OPTION('c', "config")
@@ -673,7 +681,7 @@ unknownOption:
}
}
- return Common::String();
+ return command;
}
/** List all supported game IDs, i.e. all games which any loaded plugin supports. */
@@ -891,10 +899,10 @@ static Common::String detectGames(const Common::String &path, const Common::Stri
if (candidates.empty()) {
printf("WARNING: ScummVM could not find any game in %s\n", dir.getPath().c_str());
if (noPath) {
- printf("WARNING: Consider using --path=<path> *before* --add or --detect to specify a directory\n");
+ printf("WARNING: Consider using --path=<path> to specify a directory\n");
}
if (!recursive) {
- printf("WARNING: Consider using --recursive *before* --add or --detect to search inside subdirectories\n");
+ printf("WARNING: Consider using --recursive to search inside subdirectories\n");
}
return Common::String();
}