24 if ( ( identString.
Length() == 1
26 || ( identString.
Length() >= decl->MinimumRecognitionLength()
36 if ( identString.
Length() >= decl->MinimumRecognitionLength()
61 if( param->IsOptional() ) result <<
'[';
63 result << param->Name();
64 if ( param->ValueListSeparator() !=
'\0' )
66 result <<
'[' << param->ValueListSeparator() << param->Name() <<
"...]";
69 if( param->IsOptional() ) result <<
']';
80 bool argWasPeeked=
false;
93 if( helpOpt->
Args.IsNotEmpty() )
94 argList= helpOpt->
Args.Front();
104 int cntArgsRecognized= 0;
113 int cntArgsRecognizedSoFar= cntArgsRecognized;
137 text.
Add(
"* ", param->Name() )
139 .AddMarked( param->GetHelpTextShort() )
150 if( cntArgsRecognizedSoFar == cntArgsRecognized )
172 if( cntArgsRecognizedSoFar == cntArgsRecognized )
189 if( cntArgsRecognizedSoFar == cntArgsRecognized )
191 auto& additionalHelpTopics= cmdLine.
TryResource(
"HlpAddnlTopics");
192 if( additionalHelpTopics.IsNotEmpty() )
194 Tokenizer topics(additionalHelpTopics,
',');
195 while(topics.
Next().IsNotEmpty())
212 if( cntArgsRecognized > 0 && argWasPeeked )
223 helpOpt->
Args.PushBack( argList );
229 if ( ( !argWasPeeked && cntArgsRecognized == 0 )
230 || ( cntTokens > 1 && cntArgsRecognized < cntTokens ) )
234 if( cntArgsRecognized > 0 )
250 sortedExitCodes.emplace_back(declIt);
251 std::sort( sortedExitCodes.begin(), sortedExitCodes.end(),
252 []( std::pair<Enum, ExitCodeDecl *>& lhs,
253 std::pair<Enum, ExitCodeDecl *>& rhs)
255 return lhs.first.Integral() < rhs.first.Integral();
259 for(
auto declIt : sortedExitCodes )
260 text.
Add(
" {:>3}: {}\n {}", declIt.first.Integral(),
261 declIt.second->Name(),
262 declIt.second->FormatString() );
274 text.
Add( decl->HelpUsageLine() );
284 .Add( decl->HelpTextShort(),
NEW_LINE )
299 bool argWasPeeked=
false;
300 if( dryOpt.
Args.IsNotEmpty() )
301 arg= dryOpt.
Args.Front();
313 cmdLine.
DryRun= dryRunMode;
323 else if ( !argWasPeeked )
333 dump.
Add(
"COMMANDS:")
337 dump.
Add(
"- ({}) {}", decl->Element(), decl->Identifier())
340 for(
auto& param : decl->Parameters )
341 paramIDs << param->Name() <<
", ";
346 dump.
Add(
"Associated parameters: ", paramIDs )
347 .Add( decl->HelpTextShort())
359 dump.
Add( decl->HelpUsageLine() )
360 .Add( decl->HelpText() )
372 dump.
Add(
"- ({}) {} Optional: {} Multi-Separator: {}" ,
376 (decl->ValueListSeparator() ?
Box(decl->ValueListSeparator()) :
Box(
"-/-") ))
377 .Add( decl->GetHelpTextShort())
386 dump.
Add(
"{:>5} : {}", declIt.first, declIt.second->FormatString() );
399 std::vector<Option*> options;
400 std::vector<Option*> optionsOfActType;
401 auto overallSize= optionsOriginal.
Count();
402 options .reserve(
size_t(overallSize) );
403 optionsOfActType.reserve(
size_t(overallSize) );
404 for(
auto* optionOrig : optionsOriginal )
405 options.push_back( optionOrig );
408 while( options.size() )
411 auto* decl= options.front()->Declaration;
412 optionsOfActType.clear();
414 while( actIdx < options.size() )
418 optionsOfActType.push_back( options[actIdx] );
419 options.erase( options.begin() +
static_cast<integer>(actIdx) );
426 dump.
Add(
"- \"-{},--{}\" ({}x)",
427 decl->IdentifierChar(), decl->Identifier(), optionsOfActType.size() )
430 for( actIdx= 0; actIdx < optionsOfActType.size() ; ++actIdx )
432 Option* actOption= optionsOfActType[actIdx];
433 dump.
Add(
"{}/{}: ArgStrings{!Q[]}= {!Q}, #arguments parsed: {}",
434 actIdx + 1, optionsOfActType.size(),
436 app.
GetArg(actOption->Position),
437 actOption->Args.
Count() )
441 for(
auto& arg : actOption->Args )
442 dump.
Add(
"Argument {}: {!Q}", ++argNo, arg );
458 dumpParsedOptions( cmdLine, cmdLine.
Options, dump );
461 .Add(
"OPTION ARGUMENTS IGNORED (Usable with other libs):")
465 dump.
Add(
"{}: {!Q}", cnt++ + 1, it );
471 .Add(
"COMMANDS PARSED:")
477 dump.
Add(
"- {:8}with argument #{}", cmd->Declaration->Identifier(), cmd->Position )
479 for(
auto* param : cmd->ParametersMandatory )
481 dump.
Add(
"Parameter: {}", param->Declaration->Name() )
484 for(
auto& arg : param->Args )
485 dump.
Add(
"Parameter argument {}: {!Q}", ++argNo, arg );
489 for(
auto* param : cmd->ParametersOptional )
491 dump.
Add(
"Parameter: {}", param->Declaration->Name() )
494 for(
auto& arg : param->Args )
495 dump.
Add(
"Parameter argument {}: {!Q}", ++argNo, arg );
509 .Add(
"UNRECOGNIZED CLI ARGUMENTS:")
512 dump.
Add(
"{}: {!Q}", it, cmdLine.
GetArg(it));
static ALIB_API CommandDecl * GetCommandDecl(CommandLine &cmdLine, const String &identString)
static ALIB_API ParameterDecl * GetParameterDecl(CommandLine &cmdLine, const String &identString)
static ALIB_API OptionDecl * GetOptionDecl(CommandLine &cmdLine, const String &identString)
static ALIB_API AString & DumpDeclarations(CommandLine &cmdLine, Paragraphs &text)
static ALIB_API bool GetHelp(CommandLine &cmdLine, Command *helpCmd, Option *helpOpt, Paragraphs &text)
static ALIB_API AString GetCommandUsageFormat(CommandLine &cmdLine, CommandDecl &commandDecl)
static ALIB_API AString & DumpParseResults(CommandLine &cmdLine, Paragraphs &text)
static ALIB_API bool GetDryOpt(CommandLine &cmdLine, Option &dryOpt)
const String & Identifier()
const String & HelpTextLong()
List< MonoAllocator, ParameterDecl * > Parameters
Command parameters.
List< MonoAllocator, CommandDecl * > CommandDecls
Commands defined.
List< MonoAllocator, ParameterDecl * > ParameterDecls
Possible Parameters.
HashMap< MonoAllocator, Enum, ExitCodeDecl * > ExitCodeDecls
Possible Errors.
virtual String GetArg(integer idx)
List< MonoAllocator, Command * > CommandsParsed
A list of commands actually parsed. Filled with method ReadNextCommands.
StdVectorMono< integer > ArgsLeft
const String & TryResource(const NString &name)
List< MonoAllocator, Option * > Options
The options parsed in the order of their appearance.
List< MonoAllocator, String, Recycling::Shared > OptionArgsIgnored
virtual integer ArgCount()
ALIB_API void RemoveArg(integer argNo)
const String & GetResource(const NString &name)
List< MonoAllocator, OptionDecl * > OptionDecls
Possible Options.
const String & Identifier()
const String & HelpText()
const String & HelpUsageLine()
const String & GetHelpTextLong()
ALIB_API void Reset(Snapshot snapshot=Snapshot())
TAString & DeleteEnd(integer regionLength)
void EnsureRemainingCapacity(integer spaceNeeded)
constexpr bool IsEmpty() const
constexpr bool IsNotEmpty() const
constexpr integer Length() const
TChar CharAtStart() const
integer Count(const TString &needle, integer startPos=0) const
ALIB_API TSubstring< TChar > & Next(lang::Whitespaces trimming=lang::Whitespaces::Trim, TChar newDelim='\0')
TSubstring< TChar > Actual
DryRunModes
Dry run modes.
bool Parse(strings::TSubstring< TChar > &input, TEnum &result)
lang::uinteger uinteger
Type alias in namespace alib.
std::vector< T, SCAMono< T > > StdVectorMono
Type alias in namespace alib.
constexpr CString NEW_LINE
A zero-terminated string containing the new-line character sequence.
constexpr String NULL_STRING
A nulled string of the default character type.
lang::integer integer
Type alias in namespace alib.
A command of a ALib CLI command line.
List< MonoAllocator, Parameter *, Recycling::Shared > ParametersOptional
Optional parameters parsed.
List< MonoAllocator, String, Recycling::Shared > Args
Arguments belonging to this option.
integer ConsumedArguments