Ejemplo n.º 1
0
    CompletionResult CompleteArgument(const Args& args, int argNum) {
        CommandMap& commands = GetCommandMap();

        commandLog.Debug("Completing argument %i of '%s'", argNum, args.ConcatArgs(0));

        if (args.Argc() == 0) {
            return {};
        }

        if (argNum > 0) {
            const std::string& cmdName = args.Argv(0);

            auto it = commands.find(cmdName);
            if (it == commands.end()) {
                return {};
            }

            std::string prefix;
            if (argNum < args.Argc()) {
                prefix = args.Argv(argNum);
            }

            return it->second.cmd->Complete(argNum, args, prefix);
        } else {
            return CompleteCommandNames(args.Argv(0));
        }
    }
Ejemplo n.º 2
0
 void CmdBase::PrintUsage(const Args& args, Str::StringRef syntax, Str::StringRef description) const {
     if(description.empty()) {
         Print("%s: %s %s", _("usage"), args.Argv(0).c_str(), syntax.c_str());
     } else {
         Print("%s: %s %s — %s", _("usage"), args.Argv(0).c_str(), syntax.c_str(), description.c_str());
     }
 }