Files
SedPP/include/sedpp/Options.h
T
2026-06-09 00:22:22 -05:00

57 lines
1.5 KiB
C++

#pragma once
#include <optional>
#include <string>
#include <vector>
namespace sedpp {
// A script can come from -e text or -f file text. Keeping the source kind lets
// main.cpp reproduce GNU-style diagnostics before the compiler sees the script.
struct ScriptSpec {
bool isFile = false;
std::string value;
};
// Command-line options that affect both compilation and execution. The parser
// keeps compatibility switches such as posix/strictPosix separate because some
// behavior is merely POSIX-flavored while other behavior must reject GNU syntax.
struct Options {
bool quiet = false;
bool extendedRegex = false;
bool nullData = false;
bool separate = false;
bool sandbox = false;
bool unbuffered = false;
bool posix = false;
bool strictPosix = false;
bool debug = false;
bool inPlace = false;
bool followSymlinks = false;
int lineLength = 0;
std::string inPlaceSuffix;
std::vector<std::string> scripts;
std::vector<std::string> scriptFiles;
std::vector<ScriptSpec> scriptSpecs;
std::vector<std::string> inputFiles;
};
// immediateExit is set for --help/--version and for parse-time usage errors
// where sed should exit before compiling or reading input.
struct ParseResult {
Options options;
int immediateExit = -1;
};
class OptionParser {
public:
[[nodiscard]] ParseResult parse(int argc, char **argv) const;
private:
static void printHelp(bool includeEmail, bool toStdout);
static void printVersion();
};
} // namespace sedpp