SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::CommandLine Class Reference

#include <CommandLine.hpp>

Static Public Member Functions

static std::string GetValue (const std::string &flag, const std::string &defaultVal="")
 Returns the raw string value stored for -flag, or defaultVal if it was not passed.
static bool HasFlag (const std::string &flag)
 True if --flag was present on the command line.
static void Parse (int argc, char **argv)
 Parses argv into the value/flag tables. Call once from main(), before Application.
static void SetHelpCallback (void(*callback)(const char *exe))

Detailed Description

Process-wide command line table. Parse once in main(), read anywhere.

Call Parse(argc, argv) from main() before constructing an Application. The Application reads its window size, title, and graphics backend out of this table, so skipping the call silently disables every launch flag.

Parsing rules:

  • -flag value is stored as a key/value pair, read with GetValue(). For example -r vulkan or -w 1920.
  • --flag is stored as a boolean, read with HasFlag(). For example --fullscreen.
  • --help or help invokes the callback registered with SetHelpCallback(), then parsing continues. Without a callback it is ignored.

Engine-recognized flags are -r (backend: vulkan, opengl, d3d11, d3d12), -w and -h (window size), -t (window title, with _ standing in for spaces), and --fullscreen. Game-specific flags are not declared anywhere: just read whatever you like with GetValue("-seed") or HasFlag("--fly") from your own code.

Everything is static and shared for the process.

static void PrintHelp(const char* exe) {
std::printf("Usage: %s [-r backend] [-w n] [-h n] [-seed n]\n", exe);
}
int main(int argc, char** argv) {
// ... construct Application and Run
}
// Later, in game code
uint32_t seed = std::stoul(Sleak::CommandLine::GetValue("-seed", "0"));
bool flyMode = Sleak::CommandLine::HasFlag("--fly");
static std::string GetValue(const std::string &flag, const std::string &defaultVal="")
Returns the raw string value stored for -flag, or defaultVal if it was not passed.
static void SetHelpCallback(void(*callback)(const char *exe))
static bool HasFlag(const std::string &flag)
True if --flag was present on the command line.
static void Parse(int argc, char **argv)
Parses argv into the value/flag tables. Call once from main(), before Application.
static void Init(const std::string &ProjectName)
Creates the console + file sinks and registers both loggers. Call once at startup.
Definition Logger.cpp:34
See also
Application, ApplicationDefaults, Arguments, Logger

Definition at line 53 of file CommandLine.hpp.

Member Function Documentation

◆ GetValue()

std::string Sleak::CommandLine::GetValue ( const std::string & flag,
const std::string & defaultVal = "" )
static

Returns the raw string value stored for -flag, or defaultVal if it was not passed.

Definition at line 43 of file CommandLine.cpp.

◆ HasFlag()

bool Sleak::CommandLine::HasFlag ( const std::string & flag)
static

True if --flag was present on the command line.

Definition at line 49 of file CommandLine.cpp.

◆ Parse()

void Sleak::CommandLine::Parse ( int argc,
char ** argv )
static

Parses argv into the value/flag tables. Call once from main(), before Application.

Definition at line 14 of file CommandLine.cpp.

◆ SetHelpCallback()

void Sleak::CommandLine::SetHelpCallback ( void(* callback )(const char *exe))
static

Registers the printer invoked for --help. Set it before Parse(); without one, --help is ignored.

Definition at line 10 of file CommandLine.cpp.