mirror of
https://github.com/Cameron-Reed1/Cpp-Argument-Parser.git
synced 2025-01-11 00:06:47 +00:00
Added explicit initialization for a couple variables
This commit is contained in:
parent
fbb7a689e7
commit
53e81db0ea
@ -17,8 +17,7 @@ enum ERROR {
|
|||||||
SPECIAL_CASE_HELP
|
SPECIAL_CASE_HELP
|
||||||
};
|
};
|
||||||
|
|
||||||
enum OPTTYPE
|
enum OPTTYPE {
|
||||||
{
|
|
||||||
FLAG = 0,
|
FLAG = 0,
|
||||||
STRING,
|
STRING,
|
||||||
INT
|
INT
|
||||||
@ -79,7 +78,6 @@ private:
|
|||||||
private:
|
private:
|
||||||
const char* m_program_name;
|
const char* m_program_name;
|
||||||
const char* m_description;
|
const char* m_description;
|
||||||
const char** m_argv;
|
|
||||||
uint16_t m_opt_index;
|
uint16_t m_opt_index;
|
||||||
uint16_t m_pos_index;
|
uint16_t m_pos_index;
|
||||||
std::vector<Option*> m_options;
|
std::vector<Option*> m_options;
|
||||||
|
4
Makefile
4
Makefile
@ -52,7 +52,7 @@ test_installed:
|
|||||||
$(CXX) test.cpp $(CXXFLAGS) -l$(LIB_NAME) -o $(BUILD_DIR)/test
|
$(CXX) test.cpp $(CXXFLAGS) -l$(LIB_NAME) -o $(BUILD_DIR)/test
|
||||||
-$(BUILD_DIR)/test
|
-$(BUILD_DIR)/test
|
||||||
|
|
||||||
install:
|
install: all
|
||||||
$(CP) $(BUILD_DIR)/$(LIB_FILE_NAME) $(INSTALL_DIR)
|
$(CP) $(BUILD_DIR)/$(LIB_FILE_NAME) $(INSTALL_DIR)
|
||||||
$(CP) $(HEADERS) $(HEADER_INSTALL_DIR)
|
$(CP) $(HEADERS) $(HEADER_INSTALL_DIR)
|
||||||
|
|
||||||
@ -63,4 +63,4 @@ uninstall:
|
|||||||
clean:
|
clean:
|
||||||
$(RM) -r $(BUILD_DIR)
|
$(RM) -r $(BUILD_DIR)
|
||||||
|
|
||||||
.PHONY: test install uninstall clean
|
.PHONY: all test install uninstall clean
|
||||||
|
@ -36,7 +36,7 @@ bool Option::found()
|
|||||||
}
|
}
|
||||||
|
|
||||||
PositionalArgument::PositionalArgument(const char* name, bool required, OPTTYPE type /* = STRING */)
|
PositionalArgument::PositionalArgument(const char* name, bool required, OPTTYPE type /* = STRING */)
|
||||||
: m_name(name), m_type(type), m_req(required)
|
: m_name(name), m_type(type), m_req(required), m_found(false)
|
||||||
{
|
{
|
||||||
if (type == FLAG) {
|
if (type == FLAG) {
|
||||||
std::cout << "Warning OPTTYPE 'FLAG' is not meant to be used with positional arguments" << std::endl;
|
std::cout << "Warning OPTTYPE 'FLAG' is not meant to be used with positional arguments" << std::endl;
|
||||||
@ -51,7 +51,7 @@ bool PositionalArgument::found()
|
|||||||
}
|
}
|
||||||
|
|
||||||
Parser::Parser(const char* program_name)
|
Parser::Parser(const char* program_name)
|
||||||
: m_program_name(program_name), m_description(nullptr), m_options() {}
|
: m_program_name(program_name), m_description(nullptr), m_options(), m_positional_args() {}
|
||||||
|
|
||||||
void Parser::set_description(const char* description)
|
void Parser::set_description(const char* description)
|
||||||
{
|
{
|
||||||
@ -70,6 +70,7 @@ void Parser::add_positional_argument(PositionalArgument* arg)
|
|||||||
|
|
||||||
ERROR Parser::parse(int argc, char** argv)
|
ERROR Parser::parse(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
m_pos_index = 0;
|
||||||
for (m_opt_index = 1; m_opt_index < argc; m_opt_index++)
|
for (m_opt_index = 1; m_opt_index < argc; m_opt_index++)
|
||||||
{
|
{
|
||||||
if (argv[m_opt_index][0] == '-' && argv[m_opt_index][1] == '-') {
|
if (argv[m_opt_index][0] == '-' && argv[m_opt_index][1] == '-') {
|
||||||
|
Loading…
Reference in New Issue
Block a user