Reform command-line handling to use Clara, which is bundled with Catch

This commit is contained in:
2024-08-10 15:47:26 -04:00
committed by Celtic Minstrel
parent 8801d17ed5
commit d74b11aa31
14 changed files with 124 additions and 39 deletions

5
src/tools/cli.hpp Normal file
View File

@@ -0,0 +1,5 @@
#include <boost/optional/optional_fwd.hpp>
#define CLARA_CONFIG_OPTIONAL_TYPE boost::optional
#include "clara.hpp" // part of Catch
namespace clara = Catch::clara;

View File

@@ -22,6 +22,10 @@ void setWindowFloating(sf::Window& win, bool floating);
void init_fileio();
void launchURL(std::string url);
// Optionally do some platform-specific preprocessing on the command-line arguments before parsing them.
// If preprocessing is needed, the expectation is that they will be modified in-place.
void preprocess_args(int& argc, char* argv[]);
std::string get_os_version();
fs::path nav_get_party();

View File

@@ -210,6 +210,9 @@ void launchURL(std::string url) {
system((std::string { "xdg-open " } + url).c_str());
}
void preprocess_args(int& argc, char* argv[]) {
}
// TODO: Implement modal session.
// It seems that Windows doesn't have anything similar to the Mac modal session, so I might have to somehow simulate it myself.
void ModalSession::pumpEvents() {
@@ -229,4 +232,4 @@ int getMenubarHeight() {
}
void adjust_window_for_menubar(int mode, unsigned int width, unsigned int height) {
}
}

View File

@@ -177,6 +177,28 @@ void launchURL(std::string url) {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithUTF8String:url.c_str()]]];
}
void preprocess_args(int& argc, char* argv[]) {
// Remove parameters that Xcode or the Finder throw onto the end of the command-line.
int skip_args = 0;
for(int i = 1; i < argc; i++) {
if(strcmp(argv[i], "-ApplePersistenceIgnoreState") == 0) {
skip_args = 2;
} else if(strcmp(argv[i], "-NSDocumentRevisionsDebugMode") == 0) {
skip_args = 2;
} else if(strcmp(argv[i], "-psn") == 0) {
skip_args = 1;
}
if(skip_args > 0) {
for(int j = i + 1; j <= argc; j++) {
argv[j - 1] = argv[j];
}
i--;
skip_args--;
argc--;
}
}
}
int getMenubarHeight() {
// Mac menubar isn't in the window, so we return 0 here.
return 0;

View File

@@ -426,6 +426,9 @@ void launchURL(std::string url) {
ShellExecuteA(NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
}
void preprocess_args(int& argc, char* argv[]) {
}
// TODO: Implement modal session.
// It seems that Windows doesn't have anything similar to the Mac modal session, so I might have to somehow simulate it myself.
void ModalSession::pumpEvents() {
@@ -471,4 +474,4 @@ void adjust_window_for_menubar(int mode, unsigned int width, unsigned int height
height += getMenubarHeight();
mainPtr.setSize({ width, height });
}
}