2025-01-05 13:25:40 -04:00
|
|
|
#ifndef OPTS_H
|
|
|
|
|
#define OPTS_H
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <getopt.h>
|
2025-08-13 09:43:34 -04:00
|
|
|
#include <stdexcept>
|
|
|
|
|
#include <exception>
|
2025-01-05 13:25:40 -04:00
|
|
|
|
|
|
|
|
// Define a class to hold the options and parse arguments
|
|
|
|
|
class OptionParser
|
|
|
|
|
{
|
|
|
|
|
public:
|
2025-11-06 21:40:32 -04:00
|
|
|
OptionParser() : verbose(false), printUsage(false), traceCallables(false)
|
|
|
|
|
{}
|
2025-01-05 13:25:40 -04:00
|
|
|
~OptionParser() = default;
|
|
|
|
|
|
2025-01-10 18:27:10 -04:00
|
|
|
void parseArguments(int argc, char *argv[], char **envp);
|
|
|
|
|
std::string stringifyOptions(void) const;
|
2025-01-05 13:25:40 -04:00
|
|
|
std::string getUsage() const;
|
|
|
|
|
|
2025-01-08 13:43:44 -04:00
|
|
|
static OptionParser &getOptions(void)
|
|
|
|
|
{
|
|
|
|
|
static OptionParser options;
|
|
|
|
|
return options;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-05 13:35:14 -04:00
|
|
|
public:
|
2025-08-13 09:43:34 -04:00
|
|
|
class Exception : public std::exception
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Exception() = default;
|
|
|
|
|
~Exception() override = default;
|
|
|
|
|
const char* what() const noexcept override = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-08 15:07:42 -04:00
|
|
|
std::string argv0;
|
2025-07-23 00:12:50 -04:00
|
|
|
std::vector<std::string> senseApiLibPath;
|
2025-01-08 06:19:46 -04:00
|
|
|
std::vector<std::string> senseApiLibs;
|
2025-08-29 16:12:30 -04:00
|
|
|
std::string dapSpecs;
|
|
|
|
|
std::vector<std::string> dapSpecFiles;
|
2025-11-06 21:40:32 -04:00
|
|
|
bool verbose, printUsage, traceCallables;
|
2025-01-05 13:25:40 -04:00
|
|
|
|
|
|
|
|
static struct option longOptions[];
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-13 09:43:34 -04:00
|
|
|
class OptionsParserError
|
|
|
|
|
: public std::invalid_argument, public OptionParser::Exception
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
OptionsParserError(
|
|
|
|
|
const std::string& errorMessage, const OptionParser& parser);
|
|
|
|
|
|
|
|
|
|
const char* what() const noexcept override;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class JustPrintUsageNoError
|
|
|
|
|
: public OptionParser::Exception
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit JustPrintUsageNoError(const OptionParser& parser);
|
|
|
|
|
const char* what() const noexcept override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::string message;
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-05 13:25:40 -04:00
|
|
|
#endif // OPTS_H
|