6 if ( ( identString.
Length() == 1
8 || ( identString.
Length() >= decl->MinimumRecognitionLength()
17 if ( identString.
Length() >= decl->MinimumRecognitionLength()
35 auto& appName= cmdLine.
TryResource(
"HlpCLIAppName" );
36 if( appName.IsNotEmpty() )
37 result << appName <<
' ';
42 if( param->IsOptional() ) result <<
'[';
44 result << param->Name();
45 if ( param->ValueListSeparator() !=
'\0' ) {
46 result <<
'[' << param->ValueListSeparator() << param->Name() <<
"...]";
49 if( param->IsOptional() ) result <<
']';
67 return GetHelp(cmdLine, topics, text);
72 if( helpOpt->
Args.IsNotEmpty() )
73 topics= helpOpt->
Args.front();
80 helpOpt->
Args.push_back( topics );
83 return GetHelp(cmdLine, topics, text);
93 int cntArgsRecognized= 0;
101 int cntArgsRecognizedSoFar= cntArgsRecognized;
122 text.
Add(
"* ", param->Name() )
124 .AddMarked( param->GetHelpTextShort() )
134 if( cntArgsRecognizedSoFar == cntArgsRecognized ) {
149 if( cntArgsRecognizedSoFar == cntArgsRecognized ) {
160 if( cntArgsRecognizedSoFar == cntArgsRecognized ) {
161 auto& additionalHelpTopics= cmdLine.
TryResource(
"HlpAddnlTopics");
162 if( additionalHelpTopics.IsNotEmpty() ) {
163 Tokenizer topicsTknzr(additionalHelpTopics,
',');
174 if ( ( cntArgsRecognized == 0 )
175 || ( cntTokens > 1 && cntArgsRecognized < cntTokens ) ) {
181 if( cntArgsRecognized > 0 )
198 .Add( decl->HelpTextShort(),
NEW_LINE )
206 text.
Add( decl->HelpUsageLine() );
217 sortedExitCodes.emplace_back(declIt);
218 std::sort( sortedExitCodes.begin(), sortedExitCodes.end(),
219 []( std::pair<Enum, ExitCodeDecl *>& lhs,
220 std::pair<Enum, ExitCodeDecl *>& rhs)
222 return lhs.first.Integral() < rhs.first.Integral();
226 for(
auto& declIt : sortedExitCodes )
227 text.
Add(
" {:>3}: {}\n {}", declIt.first.Integral(),
228 declIt.second->Name(),
229 declIt.second->FormatString() );
238 dump.
Add(
"COMMANDS:")
241 dump.
Add(
"- ({}) {}", decl->Element(), decl->Identifier())
244 for(
auto& param : decl->Parameters )
245 paramIDs << param->Name() <<
", ";
250 dump.
Add(
"Associated parameters: ", paramIDs )
251 .Add( decl->HelpTextShort())
262 dump.
Add( decl->HelpUsageLine() )
263 .Add( decl->HelpText() )
274 dump.
Add(
"- ({}) {} Optional: {} Multi-Separator: {}" ,
278 (decl->ValueListSeparator() ?
Box(decl->ValueListSeparator()) :
Box(
"-/-") ))
279 .Add( decl->GetHelpTextShort())
288 dump.
Add(
"{:>5} : {}", declIt.first, declIt.second->FormatString() );
301 std::vector<Option*> options;
302 std::vector<Option*> optionsOfActType;
303 auto overallSize= optionsOriginal.
size();
304 options .reserve(
size_t(overallSize) );
305 optionsOfActType.reserve(
size_t(overallSize) );
306 for(
auto* optionOrig : optionsOriginal )
307 options.push_back( optionOrig );
310 while( options.size() ) {
312 auto* decl= options.front()->Declaration;
313 optionsOfActType.clear();
315 while( actIdx < options.size() ) {
317 optionsOfActType.push_back( options[actIdx] );
318 options.erase( options.begin() +
integer(actIdx) );
325 dump.
Add(
"- \"-{},--{}\" ({}x)",
326 decl->IdentifierChar(), decl->Identifier(), optionsOfActType.size() )
329 for( actIdx= 0; actIdx < optionsOfActType.size() ; ++actIdx ) {
330 Option* actOption= optionsOfActType[actIdx];
331 dump.
Add(
"{}/{}: ArgStrings{!Q[]}= {!Q}, #arguments parsed: {}",
332 actIdx + 1, optionsOfActType.size(),
334 app.
GetArg(actOption->Position),
335 actOption->Args.
size() )
339 for(
auto& arg : actOption->Args )
340 dump.
Add(
"Argument {}: {!Q}", ++argNo, arg );
355 dumpParsedOptions( cmdLine, cmdLine.
Options, dump );
358 .Add(
"OPTION ARGUMENTS IGNORED (Usable with other libs):")
362 dump.
Add(
"{}: {!Q}", cnt++ + 1, it );
368 .Add(
"COMMANDS PARSED:")
373 dump.
Add(
"- {:8}with argument #{}", cmd->Declaration->Identifier(), cmd->Position )
375 for(
auto* param : cmd->ParametersMandatory ) {
376 dump.
Add(
"Parameter: {}", param->Declaration->Name() )
379 for(
auto& arg : param->Args )
380 dump.
Add(
"Parameter argument {}: {!Q}", ++argNo, arg );
384 for(
auto* param : cmd->ParametersOptional ) {
385 dump.
Add(
"Parameter: {}", param->Declaration->Name() )
388 for(
auto& arg : param->Args )
389 dump.
Add(
"Parameter argument {}: {!Q}", ++argNo, arg );
403 .Add(
"UNRECOGNIZED CLI ARGUMENTS:")
406 dump.
Add(
"{}: {!Q}", it, cmdLine.
GetArg(it));
#define ALIB_LOCK_RECURSIVE_WITH(lock)
static AString & DumpParseResults(CommandLine &cmdLine, Paragraphs &text)
static OptionDecl * GetOptionDecl(CommandLine &cmdLine, const String &identString)
static AString & DumpDeclarations(CommandLine &cmdLine, Paragraphs &text)
static AString GetCommandUsageFormat(CommandLine &cmdLine, CommandDecl &commandDecl)
static ParameterDecl * GetParameterDecl(CommandLine &cmdLine, const String &identString)
static CommandDecl * GetCommandDecl(CommandLine &cmdLine, const String &identString)
static bool GetHelp(CommandLine &cmdLine, const String &topics, Paragraphs &text)
const String & HelpTextLong()
ListMA< ParameterDecl * > Parameters
Command parameters.
const String & Identifier()
HashMap< MonoAllocator, Enum, ExitCodeDecl * > ExitCodeDecls
Possible Errors.
const String & TryResource(const NString &name)
ListMA< Command * > CommandsParsed
A list of commands actually parsed. Filled with method #"ReadNextCommands".
ListMA< CommandDecl * > CommandDecls
Commands defined.
ListMA< OptionDecl * > OptionDecls
Possible Options.
ListMA< ParameterDecl * > ParameterDecls
Possible Parameters.
const String & GetResource(const NString &name)
virtual String GetArg(integer idx)
ListMA< String, Recycling::Shared > OptionArgsIgnored
bool RemoveArg(integer argNo)
StdVectorMA< integer > ArgsLeft
ListMA< Option * > Options
The options parsed in the order of their appearance.
const String & HelpUsageLine()
const String & Identifier()
const String & HelpText()
const String & GetHelpTextLong()
void Reset(Snapshot snapshot=Snapshot())
TAString & DeleteEnd(integer regionLength)
TAString & ShortenTo(integer newLength)
void EnsureRemainingCapacity(integer spaceNeeded)
constexpr integer Length() const
constexpr bool IsEmpty() const
TChar CharAtStart() const
constexpr bool IsNotEmpty() const
bool StartsWith(const TString &needle) const
TSubstring< TChar > Actual
TSubstring< TChar > & Next(lang::Whitespaces trimming=lang::Whitespaces::Trim, TChar newDelim='\0')
constexpr String NULL_STRING
A nulled string of the default character type.
strings::util::TTokenizer< character > Tokenizer
Type alias in namespace #"%alib".
containers::List< T, MonoAllocator, TRecycling > ListMA
Type alias in namespace #"%alib".
constexpr CString NEW_LINE
A zero-terminated string containing the new-line character sequence.
lang::integer integer
Type alias in namespace #"%alib".
boxing::Box Box
Type alias in namespace #"%alib".
strings::TString< character > String
Type alias in namespace #"%alib".
LocalString< 256 > String256
Type alias name for #"TLocalString;TLocalString<character,256>".
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace #"%alib".
format::Paragraphs Paragraphs
Type alias in namespace #"%alib".
lang::uinteger uinteger
Type alias in namespace #"%alib".
variables::Declaration Declaration
Type alias in namespace #"%alib".
std::vector< T, StdMA< T > > StdVectorMA
Type alias in namespace #"%alib".
NLocalString< 64 > NString64
Type alias name for #"TLocalString;TLocalString<nchar,64>".
A command argument of the command-line.
ListMA< Parameter *, Recycling::Shared > ParametersOptional
Optional parameters parsed.
ListMA< String, Recycling::Shared > Args
Arguments belonging to this option.
integer ConsumedArguments