navi homeaboutscreenshotsdownloaddevelopmentforum




An ArgumentCompletionFunction? returns an ArgumentCompletionList used by the CommandExecutor to complete arguments of a ConsoleCommand. To bind an ArgumentCompletionFunction? to an argument, an ArgumentCompleter is use.


An ArgumentCompletionFunction? may take several parameters. The first parameter is the currently given argument fragment, the second parameter is the last finished argument, the third parameter is the second last finished argument etc.


There are currently 3 finished arguments and one fragment. The user wants a list of the possible arguments for the fourth argument:

> command-name argument1 argument2 argument3 fragment

Then the ArgumentCompletionFunction? of the fourth argument gets called the following way:

ac_function(fragment, argument3, argument2, argument1);

Of course the function doesn't necessarily has to take all arguments, it's possible to just use the fragment or to use no arguments at all.


Defining a new ArgumentCompletionFunction?

In core/ArgumentCompletionFunctions.h write:

                         (const std::string& fragment,  \
                          const std::string& argument1, \
                          const std::string& argument2, \

Implementing a new ArgumentCompletionFunction?

In core/ write:

                            (const std::string& fragment,  \
                             const std::string& argument1, \
                             const std::string& argument2, \
    ArgumentCompletionList myList;

    for (some_condition)
        std::string argument, lowercase, display;

        argument  = some_logic1();
        lowercase = some_logic2();
        display   = some_logic3();

        ArgumentCompletionListElement element(argument, lowercase, display)

    return myList;

Note: lowercase and display in the constructor of ArgumentCompletionListElement? are optional. If not specified, the first string (argument) is used.


The following example implements an ArgumentCompletionList returning a set of possible names for girls or boys:

In core/ArgumentCompletionFunctions.h:

    (const std::string& fragment, const std::string& gender);

In core/

    (const std::string& fragment, const std::string& gender)
    ArgumentCompletionList myList;

    if (gender == "boy")
        myList.push_back(ArgumentCompletionListElement("Bob", "bob"));
        myList.push_back(ArgumentCompletionListElement("John", "john"));
        myList.push_back(ArgumentCompletionListElement("Elton", "elton"));
        myList.push_back(ArgumentCompletionListElement("Bruce", "bruce"));
    else if (gender == "girl")
        myList.push_back(ArgumentCompletionListElement("Jessica", "jessica"));
        myList.push_back(ArgumentCompletionListElement("Amanda", "amanda"));
        myList.push_back(ArgumentCompletionListElement("Kate", "kate"));
        myList.push_back(ArgumentCompletionListElement("Angelina", "angelina"));

    return myList;

Now it's possible to complete names:

> command-name boy
Possible arguments: Bob, Bruce, Elton, John

> command-name boy b
Possible arguments: Bob, Bruce

> command-name boy bo
Possible arguments: Bob

> command-name girl je
Possible arguments: Jessica

> command-name girl jennif
Possible arguments: -
Last modified 8 years ago Last modified on Oct 7, 2008, 2:51:19 PM