diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index d890663b..1863562d 100644 --- a/src/commands/CmdHelp.cpp +++ b/src/commands/CmdHelp.cpp @@ -24,69 +24,16 @@ // //////////////////////////////////////////////////////////////////////////////// -#include #include #include -#include #include -#include #include -#include - +#include #include "additional-help.h" -template -std::string join (const T& strings, size_t indent = 0, size_t max_width = 0) -{ - std::stringstream sstr; - auto it = std::begin (strings); - auto end = std::end (strings); - size_t cur = indent + 2; // account for added '{ ' - std::string part; - const std::string sep (" | "); - - while (it != end) - { - part = *it; - ++it; - - // Make sure we leave room for closing " }" or " |" - if ((max_width > 0) && (cur + part.length () + sep.length ()) > max_width) - { - sstr << "\n" << std::string (indent + 1, ' '); - cur = indent + 1; - sstr << part; - } - else - { - sstr << part; - } - cur += part.length (); - - if (it != end) - { - sstr << sep; - cur += sep.length (); - } - } - return sstr.str (); -} - //////////////////////////////////////////////////////////////////////////////// int CmdHelpUsage (const Extensions& extensions) { - std::vector concepts; - - // Any commands will take precedence when using `timew help` and therefore, - // we'll exclude any commands that are also concepts. - std::set_difference (std::begin (documented_concepts), std::end (documented_concepts), - std::begin (documented_commands), std::end (documented_commands), - std::back_inserter (concepts), - [] (const char *a, const char *b) - { - return std::strcmp (a, b) < 0; - }); - std::cout << '\n' << "Usage: timew [--version]\n" << " timew annotate @ [@ ...] \n" @@ -100,7 +47,7 @@ int CmdHelpUsage (const Extensions& extensions) << " timew extensions\n" << " timew gaps [] [ ...]\n" << " timew get [ ...]\n" - << " timew help [ | " << join (concepts) << "]\n" + << " timew help [ | " << join ( " | ", timew_help_concepts) << "]\n" << " timew join @ @\n" << " timew lengthen @ [@ ...] \n" << " timew modify (start|end) @ \n" @@ -135,7 +82,8 @@ int CmdHelpUsage (const Extensions& extensions) std::cout << "Additional help:\n" << " timew help \n"; - for (auto concept : concepts) + + for (auto& concept : timew_help_concepts) { std::cout << " timew help " << concept << '\n'; } diff --git a/src/commands/generate-additional-help.sh b/src/commands/generate-additional-help.sh index e340a8d9..5cd64f01 100644 --- a/src/commands/generate-additional-help.sh +++ b/src/commands/generate-additional-help.sh @@ -1,14 +1,13 @@ #!/bin/sh -echo "// Generated file. Do not modify" -echo "static const char * documented_concepts[] = {" -for command in $(/bin/ls doc/man7/*.in | /bin/sed -n 's|doc/man7/timew-\(\w\+\).7.in|\1|p' | /usr/bin/sort); do - echo " \"${command}\"," -done -echo "};" +CONCEPTS="$( ls doc/man7/*.in | sed -E 's|doc/man7/timew-(.*).7.in|\1|' | sort )" +COMMANDS="$( ls doc/man1/*.in | sed -E 's|doc/man1/timew-(.*).1.in|\1|' | sort | tr '\n' ' ' )" -echo "static const char * documented_commands[] = {" -for command in $(/bin/ls doc/man1/*.in | /bin/sed -n 's|doc/man1/timew-\(\w\+\).1.in|\1|p' | /usr/bin/sort); do - echo " \"${command}\"," +echo "// Generated file. Do not modify" +echo "#include " +echo "#include " +echo "static const std::vector timew_help_concepts = {" +for concept in ${CONCEPTS} ; do + ( echo "${COMMANDS}" | grep -vq "${concept}" ) && echo " \"${concept}\"," done echo "};"