From ae24c9056d05b5f3ebe90cf4c345a986a6539bf4 Mon Sep 17 00:00:00 2001 From: JF Bastien Date: Sat, 2 Jan 2016 13:49:11 -0800 Subject: Generalize command-line parsing more. This should allow other programs to use the same command-line support. --- src/support/command-line.h | 50 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 10 deletions(-) (limited to 'src/support/command-line.h') diff --git a/src/support/command-line.h b/src/support/command-line.h index f57929b6b..14dbce57f 100644 --- a/src/support/command-line.h +++ b/src/support/command-line.h @@ -21,22 +21,52 @@ #ifndef wasm_support_command_line_h #define wasm_support_command_line_h +#include +#include +#include +#include +#include + #include "wasm.h" + namespace wasm { -struct Options { - // standard options +class Options { + public: + typedef std::function Action; + enum class Arguments { Zero, One, N }; + bool debug; - std::string infile; - std::string outfile; - // extra options - std::map extra; - Options() : debug(false) {} -}; + std::map extra; -void processCommandLine(int argc, const char *argv[], Options *options, - const char *help); + Options(const std::string &command, const std::string &description); + ~Options(); + Options &add(const std::string &longName, const std::string &shortName, + const std::string &description, Arguments arguments, + const Action &action); + Options &add_positional(const std::string &name, Arguments arguments, + const Action &action); + void parse(int argc, const char *argv[]); + + private: + Options() = delete; + Options(const Options &) = delete; + Options &operator=(const Options &) = delete; + + struct Option { + std::string longName; + std::string shortName; + std::string description; + Arguments arguments; + Action action; + size_t seen; + }; + std::vector