| 221 | } |
| 222 | |
| 223 | void CLICommand::ShowCommands(int argc, char **argv, po::options_description *visibleDesc, |
| 224 | ArgumentCompletionCallback globalArgCompletionCallback, |
| 225 | bool autocomplete, int autoindex) |
| 226 | { |
| 227 | std::unique_lock<std::mutex> lock(GetRegistryMutex()); |
| 228 | |
| 229 | typedef std::map<std::vector<String>, CLICommand::Ptr>::value_type CLIKeyValue; |
| 230 | |
| 231 | std::vector<String> best_match; |
| 232 | CLICommand::Ptr command; |
| 233 | |
| 234 | for (const CLIKeyValue& kv : GetRegistry()) { |
| 235 | const std::vector<String>& vname = kv.first; |
| 236 | |
| 237 | std::vector<String>::size_type i; |
| 238 | int k; |
| 239 | for (i = 0, k = 1; i < vname.size() && k < argc; i++, k++) { |
| 240 | if (strcmp(argv[k], "--no-stack-rlimit") == 0 || strcmp(argv[k], "--autocomplete") == 0 || strcmp(argv[k], "--scm") == 0) { |
| 241 | i--; |
| 242 | continue; |
| 243 | } |
| 244 | |
| 245 | if (autocomplete && static_cast<int>(i) >= autoindex - 1) |
| 246 | break; |
| 247 | |
| 248 | if (vname[i] != argv[k]) |
| 249 | break; |
| 250 | |
| 251 | if (i >= best_match.size()) { |
| 252 | best_match.push_back(vname[i]); |
| 253 | } |
| 254 | |
| 255 | if (i == vname.size() - 1) { |
| 256 | command = kv.second; |
| 257 | break; |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | String aword; |
| 263 | |
| 264 | if (autocomplete) { |
| 265 | if (autoindex < argc) |
| 266 | aword = argv[autoindex]; |
| 267 | |
| 268 | if (autoindex - 1 > static_cast<int>(best_match.size()) && !command) |
| 269 | return; |
| 270 | } else |
| 271 | std::cout << "Supported commands: " << std::endl; |
| 272 | |
| 273 | for (const CLIKeyValue& kv : GetRegistry()) { |
| 274 | const std::vector<String>& vname = kv.first; |
| 275 | |
| 276 | if (vname.size() < best_match.size() || kv.second->IsHidden()) |
| 277 | continue; |
| 278 | |
| 279 | bool match = true; |
| 280 |
nothing calls this directly
no test coverage detected