Browse Source

Switching to argagg for CLI parsing

pull/1005/head
jfrey 7 years ago
parent
commit
95a7650b8d
4 changed files with 37 additions and 12 deletions
  1. +3
    -0
      .gitmodules
  2. +5
    -1
      dep/Makefile
  3. +1
    -0
      dep/argagg
  4. +28
    -11
      src/main.cpp

+ 3
- 0
.gitmodules View File

@@ -16,3 +16,6 @@
[submodule "dep/rtaudio"] [submodule "dep/rtaudio"]
path = dep/rtaudio path = dep/rtaudio
url = https://github.com/thestk/rtaudio.git url = https://github.com/thestk/rtaudio.git
[submodule "dep/argagg"]
path = dep/argagg
url = https://github.com/vietjtnguyen/argagg.git

+ 5
- 1
dep/Makefile View File

@@ -50,8 +50,9 @@ nanosvg = include/nanosvg.h
oui-blendish = include/blendish.h oui-blendish = include/blendish.h
osdialog = include/osdialog.h osdialog = include/osdialog.h
pffft = include/pffft.h pffft = include/pffft.h
argagg = include/argagg.hpp


DEPS += $(glew) $(glfw) $(jansson) $(libspeexdsp) $(libcurl) $(libzip) $(rtmidi) $(rtaudio) $(nanovg) $(nanosvg) $(oui-blendish) $(osdialog) $(pffft)
DEPS += $(glew) $(glfw) $(jansson) $(libspeexdsp) $(libcurl) $(libzip) $(rtmidi) $(rtaudio) $(nanovg) $(nanosvg) $(oui-blendish) $(osdialog) $(pffft) $(argagg)
include $(RACK_DIR)/dep.mk include $(RACK_DIR)/dep.mk




@@ -163,6 +164,9 @@ $(pffft):
$(WGET) "https://bitbucket.org/jpommier/pffft/get/29e4f76ac53b.zip" $(WGET) "https://bitbucket.org/jpommier/pffft/get/29e4f76ac53b.zip"
$(UNZIP) 29e4f76ac53b.zip $(UNZIP) 29e4f76ac53b.zip
cp jpommier-pffft-29e4f76ac53b/*.h include/ cp jpommier-pffft-29e4f76ac53b/*.h include/
$(argagg): $(wildcard argagg/include/argagg/*.hpp)
cp argagg/include/argagg/*.hpp include/


clean: clean:
git clean -fdx git clean -fdx


+ 1
- 0
dep/argagg

@@ -0,0 +1 @@
Subproject commit 24f1dd7fd222b2c70b1f02109761f6bc698e5f68

+ 28
- 11
src/main.cpp View File

@@ -13,6 +13,8 @@
#include "util/color.hpp" #include "util/color.hpp"


#include "osdialog.h" #include "osdialog.h"
#include "argagg.hpp"

#include <unistd.h> #include <unistd.h>




@@ -24,18 +26,33 @@ int main(int argc, char* argv[]) {
std::string patchFile; std::string patchFile;


// Parse command line arguments // Parse command line arguments
int c;
opterr = 0;
while ((c = getopt(argc, argv, "d")) != -1) {
switch (c) {
case 'd': {
devMode = true;
} break;
default: break;
}
argagg::parser argparser {{
{ "help", {"-h", "--help"}, "shows this help message", 0},
{ "devmod", {"-d", "--devmod"}, "enable dev mode", 0},
}};

argagg::parser_results args;

try {
args = argparser.parse(argc, argv);
} catch (const std::exception& e) {
std::cerr << "Encountered exception while parsing arguments: " << e.what() << std::endl;
return EXIT_FAILURE;
} }
if (optind < argc) {
patchFile = argv[optind];

if (args["help"]) {
std::cerr << "Usage: program [options] [FILENAME]" << std::endl;
std::cerr << argparser;
return EXIT_SUCCESS;
}

if (args["devmod"]) {
devMode = true;
}

// Filename as first positional argument
if (args.pos.size() > 0) {
patchFile = args.as<std::string>(0);
} }


// Initialize environment // Initialize environment


Loading…
Cancel
Save