From 11c8a4d1e64bbe57619a2af6ef560cf8fd0c5d6c Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 13 Mar 2019 13:44:05 +0000 Subject: [PATCH] Added a method ConsoleApplication::printCommandDetails() --- .../misc/juce_ConsoleApplication.cpp | 52 ++++++++++++------- .../juce_core/misc/juce_ConsoleApplication.h | 5 ++ 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/modules/juce_core/misc/juce_ConsoleApplication.cpp b/modules/juce_core/misc/juce_ConsoleApplication.cpp index f461180266..3988e4b120 100644 --- a/modules/juce_core/misc/juce_ConsoleApplication.cpp +++ b/modules/juce_core/misc/juce_ConsoleApplication.cpp @@ -386,37 +386,51 @@ const std::vector& ConsoleApplication::getCommands( return commands; } -void ConsoleApplication::printCommandList (const ArgumentList& args) const +static String getExeNameAndArgs (const ArgumentList& args, const ConsoleApplication::Command& command) { auto exeName = args.executableName.fromLastOccurrenceOf ("/", false, false) .fromLastOccurrenceOf ("\\", false, false); - StringArray namesAndArgs; + return " " + exeName + " " + command.argumentDescription; +} + +static void printCommandDescription (const ArgumentList& args, const ConsoleApplication::Command& command, + int descriptionIndent) +{ + auto nameAndArgs = getExeNameAndArgs (args, command); + + if (nameAndArgs.length() > descriptionIndent) + std::cout << nameAndArgs << std::endl << String().paddedRight (' ', descriptionIndent); + else + std::cout << nameAndArgs.paddedRight (' ', descriptionIndent); + + std::cout << command.shortDescription << std::endl; +} + +void ConsoleApplication::printCommandList (const ArgumentList& args) const +{ int descriptionIndent = 0; for (auto& c : commands) - { - auto nameAndArgs = exeName + " " + c.argumentDescription; - namesAndArgs.add (nameAndArgs); - descriptionIndent = std::max (descriptionIndent, nameAndArgs.length()); - } + descriptionIndent = std::max (descriptionIndent, getExeNameAndArgs (args, c).length()); - descriptionIndent = std::min (descriptionIndent + 1, 40); + descriptionIndent = std::min (descriptionIndent + 2, 40); - for (size_t i = 0; i < commands.size(); ++i) - { - auto nameAndArgs = namesAndArgs[(int) i]; - std::cout << ' '; + for (auto& c : commands) + printCommandDescription (args, c, descriptionIndent); - if (nameAndArgs.length() > descriptionIndent) - std::cout << nameAndArgs << std::endl << String::repeatedString (" ", descriptionIndent + 1); - else - std::cout << nameAndArgs.paddedRight (' ', descriptionIndent); + std::cout << std::endl; +} - std::cout << commands[i].shortDescription << std::endl; - } +void ConsoleApplication::printCommandDetails (const ArgumentList& args, const Command& command) const +{ + auto len = getExeNameAndArgs (args, command).length(); - std::cout << std::endl; + printCommandDescription (args, command, std::min (len + 3, 40)); + + if (command.longDescription.isNotEmpty()) + std::cout << std::endl << command.longDescription << std::endl; } + } // namespace juce diff --git a/modules/juce_core/misc/juce_ConsoleApplication.h b/modules/juce_core/misc/juce_ConsoleApplication.h index 6cdacf08b3..bc46c51440 100644 --- a/modules/juce_core/misc/juce_ConsoleApplication.h +++ b/modules/juce_core/misc/juce_ConsoleApplication.h @@ -281,6 +281,11 @@ struct ConsoleApplication */ void printCommandList (const ArgumentList&) const; + /** Prints out a longer description of a particular command, based on its + longDescription member. + */ + void printCommandDetails (const ArgumentList&, const Command&) const; + //============================================================================== /** Throws a failure exception to cause a command-line app to terminate. This is intended to be called from code in a Command, so that the