summaryrefslogtreecommitdiffstats
path: root/src/command_line_options.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/command_line_options.cpp')
-rw-r--r--src/command_line_options.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/command_line_options.cpp b/src/command_line_options.cpp
new file mode 100644
index 0000000..4ee6520
--- /dev/null
+++ b/src/command_line_options.cpp
@@ -0,0 +1,54 @@
+#include "command_line_options.h"
+#include <getopt.h>
+
+CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) {
+ // parse command line arguments
+ for (;;) {
+ static const struct option longOptions[] = {
+ {"config", required_argument, NULL, 'c'},
+ {"default", required_argument, NULL, 'd'},
+ {"path", required_argument, NULL, 'p'},
+ {"xpath", required_argument, NULL, 'x'},
+ {"size", required_argument, NULL, 's'},
+ {"version", no_argument, NULL, 'v'},
+ {"help", no_argument, NULL, 'h'}
+ };
+
+ int opt = getopt_long(argc, argv, "c:d:p:x:s:vhb", longOptions, NULL);
+ if (opt == -1) break;
+
+ switch (opt) {
+ case 'c':
+ options.insert("config", optarg);
+ break;
+ case 'd':
+ options.insert("default", optarg);
+ break;
+ case 'p':
+ options.insert("path", optarg);
+ break;
+ case 'x':
+ options.insert("xpath", optarg);
+ break;
+ case 's':
+ options.insert("size", optarg);
+ break;
+ case 'v':
+ options.insert("version", "version");
+ break;
+ case 'h':
+ options.insert("usage", "usage");
+ break;
+ case '?':
+ default:
+ options.insert("error", "error");
+ }
+
+ if (optind == argc - 1) {
+ options.insert("file", argv[optind]);
+ } else if (optind < argc - 1) {
+ options.insert("error", "error");
+ }
+ }
+}
+