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

Remove unhelpful ParseArgs help text validation #17394

Merged
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
46 changes: 0 additions & 46 deletions src/lib/support/CHIPArgParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ static void PutStringWithNewLine(FILE * s, const char * str);
static void PutStringWithBlankLine(FILE * s, const char * str);
#if CHIP_CONFIG_ENABLE_ARG_PARSER_VALIDITY_CHECKS
static bool SanityCheckOptions(OptionSet * optSets[]);
static bool HelpTextContainsLongOption(const char * optName, const char * helpText);
static bool HelpTextContainsShortOption(char optChar, const char * helpText);
#endif // CHIP_CONFIG_ENABLE_ARG_PARSER_VALIDITY_CHECKS

static inline bool IsShortOptionChar(int ch)
Expand Down Expand Up @@ -1511,53 +1509,9 @@ static bool SanityCheckOptions(OptionSet * optSets[])
}
}

// Fail if the option help texts do not contain a description for each option, including both
// the option's long and short forms.
for (OptionSet ** optSetP = optSets; *optSetP != nullptr; optSetP++)
for (OptionDef * optionDef = (*optSetP)->OptionDefs; optionDef->Name != nullptr; optionDef++)
{
if (!HelpTextContainsLongOption(optionDef->Name, (*optSetP)->OptionHelp))
{
PrintArgError("INTERNAL ERROR: No help text defined for option: --%s\n", optionDef->Name);
res = false;
}

if (IsShortOptionChar(optionDef->Id) &&
!HelpTextContainsShortOption(static_cast<char>(optionDef->Id), (*optSetP)->OptionHelp))
{
PrintArgError("INTERNAL ERROR: No help text defined for option: -%c\n", optionDef->Id);
res = false;
}
}

return res;
}

static bool HelpTextContainsLongOption(const char * optName, const char * helpText)
{
size_t nameLen = strlen(optName);

for (const char * p = helpText; (p = strstr(p, optName)) != nullptr; p += nameLen)
if ((p - helpText) >= 2 && p[-1] == '-' && p[-2] == '-' && !isalnum(p[nameLen]) && p[nameLen] != '-')
return true;

return false;
}

static bool HelpTextContainsShortOption(char optChar, const char * helpText)
{
char optStr[3];
optStr[0] = '-';
optStr[1] = optChar;
optStr[2] = 0;

for (const char * p = helpText; (p = strstr(p, optStr)) != nullptr; p += 2)
if ((p == helpText || (!isalnum(p[-1]) && p[-1] != '-')) && !isalnum(p[2]) && p[2] != '-')
return true;

return false;
}

#endif // CHIP_CONFIG_ENABLE_ARG_PARSER_VALIDITY_CHECKS

} // namespace ArgParser
Expand Down