BEEP-8 Helper Lib 1.0.0
Loading...
Searching...
No Matches
argparse.h File Reference

Command-line argument parser for C++. More...

#include <string>
#include <vector>
#include <map>

Go to the source code of this file.

Classes

struct  argparse::Argument
 Structure representing a command line argument. More...
 
struct  argparse::Var
 Structure representing a variable associated with an argument. More...
 
class  argparse::ArgumentParser
 Class for parsing command line arguments. More...
 

Detailed Description

Command-line argument parser for C++.

This header file defines the structures and classes needed for parsing command-line arguments in C++. It includes functionality to define arguments, parse them, and retrieve their values. The parser supports both long and short argument names, as well as different types of actions such as storing boolean values and displaying help messages.

Example usage:

#include "argparse.h"
int main(int argc, char* argv[]) {
parser.AddArgument("--verbose", "-v", "Enable verbose mode", argparse::Argument::store_true);
parser.AddArgument("--output", "-o", "Output file name");
auto result = parser.ParseArgs(std::vector<std::string>(argv + 1, argv + argc));
return result;
}
bool verbose = parser.GetVarInt("--verbose", 0);
std::string output = parser.GetVarStr("--output", "default.txt");
// Your program logic here
}
Command-line argument parser for C++.
Class for parsing command line arguments.
Definition argparse.h:113
int GetVarInt(std::string name_, int if_not_found_)
Get the integer value of a variable.
Definition argparse.cpp:111
@ OK
Parsing successful.
Definition argparse.h:122
Result ParseArgs(const std::vector< std::string > &args)
Parse command line arguments.
Definition argparse.cpp:58
int AddArgument(std::string name_, std::string short_alias_, std::string help_, Argument::Action action_=Argument::store_true)
Add an argument to the parser.
Definition argparse.cpp:141
std::string GetVarStr(std::string name_, std::string if_not_found_)
Get the string value of a variable.
Definition argparse.cpp:116
@ store_true
Store true (1)
Definition argparse.h:82

This module is primarily designed for tool development purposes rather than game development. It is not essential for game creation but is available for use if needed.

Version
1.0
Date
2022
Author
ZooK

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.