Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the positionnal option to make parser stop on first unknown option #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion SimpleOpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ enum _ESOFlags
SO_O_ICASE_WORD = 0x0400,

/*! Case-insensitive comparisons for all arg types */
SO_O_ICASE = 0x0700
SO_O_ICASE = 0x0700,

/*! Set the parser stop at first unvalid option*/
SO_O_POSITIONAL = 0x0800
};

/*! Types of arguments that options may have. Note that some of the _ESOFlags
Expand Down Expand Up @@ -679,6 +682,11 @@ CSimpleOptTempl<SOCHAR>::Next()
// and we are not suppressing errors for invalid options then it
// is reported as an error, otherwise it is data.
if (nTableIdx < 0) {
if (HasFlag(SO_O_POSITIONAL)) {
Stop();
return false;
}

if (!HasFlag(SO_O_NOERR) && pszArg[0] == (SOCHAR)'-') {
m_pszOptionText = pszArg;
break;
Expand Down