mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 21:47:00 -04:00
Clean up command line argument handling a bit
This commit is contained in:
+28
-25
@@ -96,11 +96,17 @@ int MSE::OnRun() {
|
|||||||
nag_about_ascii_version();
|
nag_about_ascii_version();
|
||||||
|
|
||||||
// interpret command line
|
// interpret command line
|
||||||
if (argc > 1) {
|
{
|
||||||
try {
|
// ingnore the --color argument, it is handled by cli.init()
|
||||||
String arg = argv[1];
|
vector<String> args;
|
||||||
|
for (int i = 1; i < argc; ++i) {
|
||||||
|
args.push_back(argv[i]);
|
||||||
|
if (args.back() == _("--color")) args.pop_back();
|
||||||
|
}
|
||||||
|
if (!args.empty()) {
|
||||||
|
const String& arg = args[0];
|
||||||
// Find the extension
|
// Find the extension
|
||||||
wxFileName f(arg.Mid(0,arg.find_last_not_of(_("\\/"))+1));
|
wxFileName f(arg.Mid(0,arg.find_last_not_of(_("\\/")) + 1));
|
||||||
if (f.GetExt() == _("mse-symbol")) {
|
if (f.GetExt() == _("mse-symbol")) {
|
||||||
// Show the symbol editor
|
// Show the symbol editor
|
||||||
Window* wnd = new SymbolWindow(nullptr, arg);
|
Window* wnd = new SymbolWindow(nullptr, arg);
|
||||||
@@ -114,10 +120,9 @@ int MSE::OnRun() {
|
|||||||
} else if (f.GetExt() == _("mse-installer")) {
|
} else if (f.GetExt() == _("mse-installer")) {
|
||||||
// Installer; install it
|
// Installer; install it
|
||||||
InstallType type = settings.install_type;
|
InstallType type = settings.install_type;
|
||||||
if (argc > 2) {
|
if (args.size() > 1) {
|
||||||
String arg = argv[2];
|
if (starts_with(args[1], _("--"))) {
|
||||||
if (starts_with(argv[2], _("--")) && arg != _("--color")) {
|
parse_enum(String(args[1]).substr(2), type);
|
||||||
parse_enum(String(argv[2]).substr(2), type);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
InstallerP installer = open_package<Installer>(argv[1]);
|
InstallerP installer = open_package<Installer>(argv[1]);
|
||||||
@@ -136,9 +141,9 @@ int MSE::OnRun() {
|
|||||||
} else if (arg == _("--create-installer")) {
|
} else if (arg == _("--create-installer")) {
|
||||||
// create an installer
|
// create an installer
|
||||||
Installer inst;
|
Installer inst;
|
||||||
for (int i = 2 ; i < argc ; ++i) {
|
FOR_EACH(arg, args) {
|
||||||
if (!starts_with(argv[i],_("--"))) {
|
if (!starts_with(arg, _("--"))) {
|
||||||
inst.addPackage(argv[i]);
|
inst.addPackage(arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (inst.prefered_filename.empty()) {
|
if (inst.prefered_filename.empty()) {
|
||||||
@@ -196,7 +201,7 @@ int MSE::OnRun() {
|
|||||||
cli << ENDL;
|
cli << ENDL;
|
||||||
cli.flush();
|
cli.flush();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
} else if (arg == _("--version") || arg == _("-v")) {
|
} else if (arg == _("--version") || arg == _("-v") || arg == _("-V")) {
|
||||||
// dump version
|
// dump version
|
||||||
cli << _("Magic Set Editor\n");
|
cli << _("Magic Set Editor\n");
|
||||||
cli << _("Version ") << app_version.toString() << version_suffix << ENDL;
|
cli << _("Version ") << app_version.toString() << version_suffix << ENDL;
|
||||||
@@ -206,9 +211,9 @@ int MSE::OnRun() {
|
|||||||
// command line interface
|
// command line interface
|
||||||
SetP set;
|
SetP set;
|
||||||
bool quiet = false;
|
bool quiet = false;
|
||||||
for (int i = 2 ; i < argc ; ++i) {
|
for (size_t i = 1; i < args.size(); ++i) {
|
||||||
String arg = argv[i];
|
String const& arg = args[i];
|
||||||
wxFileName f(argv[i]);
|
wxFileName f(arg);
|
||||||
if (f.GetExt() == _("mse-set") || f.GetExt() == _("mse") || f.GetExt() == _("set")) {
|
if (f.GetExt() == _("mse-set") || f.GetExt() == _("mse") || f.GetExt() == _("set")) {
|
||||||
set = import_set(arg);
|
set = import_set(arg);
|
||||||
} else if (arg == _("-q") || arg == _("--quiet")) {
|
} else if (arg == _("-q") || arg == _("--quiet")) {
|
||||||
@@ -221,32 +226,29 @@ int MSE::OnRun() {
|
|||||||
CLISetInterface cli_interface(set,quiet);
|
CLISetInterface cli_interface(set,quiet);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
} else if (arg == _("--export")) {
|
} else if (arg == _("--export")) {
|
||||||
if (argc <= 2 || (argc <= 3 && starts_with(argv[2],_("--")))) {
|
if (args.size() < 2) {
|
||||||
handle_error(Error(_("No input file specified for --export")));
|
handle_error(Error(_("No input file specified for --export")));
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
SetP set = import_set(argv[2]);
|
SetP set = import_set(args[1]);
|
||||||
// path
|
// path
|
||||||
String out = argc >= 3 && !starts_with(argv[3],_("--"))
|
String out = args.size() >= 3 && !starts_with(args[2], _("--"))
|
||||||
? argv[3]
|
? args[2]
|
||||||
: settings.gameSettingsFor(*set->game).images_export_filename;
|
: settings.gameSettingsFor(*set->game).images_export_filename;
|
||||||
String path = _(".");
|
String path = _(".");
|
||||||
size_t pos = out.find_last_of(_("/\\"));
|
size_t pos = out.find_last_of(_("/\\"));
|
||||||
if (pos != String::npos) {
|
if (pos != String::npos) {
|
||||||
path = out.substr(0, pos);
|
path = out.substr(0, pos);
|
||||||
if (!wxDirExists(path)) wxMkdir(path);
|
if (!wxDirExists(path)) wxMkdir(path);
|
||||||
path += _("/x");
|
path += _("/x");
|
||||||
out = out.substr(pos + 1);
|
out = out.substr(pos + 1);
|
||||||
}
|
}
|
||||||
// export
|
// export
|
||||||
export_images(set, set->cards, path, out, CONFLICT_NUMBER_OVERWRITE);
|
export_images(set, set->cards, path, out, CONFLICT_NUMBER_OVERWRITE);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
handle_error(_("Invalid command line argument:\n") + String(argv[1]));
|
handle_error(_("Invalid command line argument:\n") + arg);
|
||||||
}
|
}
|
||||||
} catch (const Error& e) {
|
|
||||||
handle_error(e);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,6 +257,7 @@ int MSE::OnRun() {
|
|||||||
return runGUI();
|
return runGUI();
|
||||||
|
|
||||||
} CATCH_ALL_ERRORS(true);
|
} CATCH_ALL_ERRORS(true);
|
||||||
|
cli.print_pending_errors();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user