| 160 | } |
| 161 | |
| 162 | void ArgumentParser::SubCommandDescriptor::help(std::FILE *Out) const noexcept { |
| 163 | // For enabling Windows PowerShell color support. |
| 164 | #if WASMEDGE_OS_WINDOWS && WINAPI_PARTITION_DESKTOP |
| 165 | winapi::HANDLE_ OutputHandler = |
| 166 | winapi::GetStdHandle(winapi::STD_OUTPUT_HANDLE_); |
| 167 | if (OutputHandler != winapi::INVALID_HANDLE_VALUE_) { |
| 168 | winapi::DWORD_ ConsoleMode = 0; |
| 169 | if (winapi::GetConsoleMode(OutputHandler, &ConsoleMode)) { |
| 170 | ConsoleMode |= winapi::ENABLE_VIRTUAL_TERMINAL_PROCESSING_; |
| 171 | winapi::SetConsoleMode(OutputHandler, ConsoleMode); |
| 172 | } |
| 173 | } |
| 174 | #endif |
| 175 | |
| 176 | usage(Out); |
| 177 | const constexpr std::string_view kIndent = "\t"sv; |
| 178 | |
| 179 | fmt::print(Out, "\n"sv); |
| 180 | if (!SubCommandList.empty()) { |
| 181 | fmt::print(Out, "{}SUBCOMMANDS{}\n"sv, YELLOW_COLOR, RESET_COLOR); |
| 182 | for (const auto Offset : SubCommandList) { |
| 183 | fmt::print(Out, "{}{}"sv, kIndent, GREEN_COLOR); |
| 184 | bool First = true; |
| 185 | for (const auto &Name : this[Offset].SubCommandNames) { |
| 186 | if (!First) { |
| 187 | fmt::print(Out, "|"sv); |
| 188 | } |
| 189 | fmt::print(Out, "{}"sv, Name); |
| 190 | First = false; |
| 191 | } |
| 192 | fmt::print(Out, "{}\n"sv, RESET_COLOR); |
| 193 | indent_output(Out, kIndent, 2, 80, this[Offset].SC->description()); |
| 194 | fmt::print(Out, "\n"sv); |
| 195 | } |
| 196 | fmt::print(Out, "\n"sv); |
| 197 | } |
| 198 | |
| 199 | fmt::print(Out, "{}OPTIONS{}\n"sv, YELLOW_COLOR, RESET_COLOR); |
| 200 | for (const auto &Index : NonpositionalList) { |
| 201 | const auto &Desc = ArgumentDescriptors[Index]; |
| 202 | if (Desc.hidden()) { |
| 203 | continue; |
| 204 | } |
| 205 | |
| 206 | fmt::print(Out, "{}{}\n"sv, kIndent, GREEN_COLOR); |
| 207 | bool First = true; |
| 208 | for (const auto &Option : Desc.options()) { |
| 209 | if (!First) { |
| 210 | fmt::print(Out, "|"sv); |
| 211 | } |
| 212 | if (Option.size() == 1) { |
| 213 | fmt::print(Out, "-{}"sv, Option); |
| 214 | } else { |
| 215 | fmt::print(Out, "--{}"sv, Option); |
| 216 | } |
| 217 | First = false; |
| 218 | } |
| 219 | fmt::print(Out, "{}\n"sv, RESET_COLOR); |
nothing calls this directly
no test coverage detected