Bind text commands to actions in your program.
This console is on the "Game Console" created by Michael König and presented at the August Meetup of the C++ User Group Zurich.
It has been heavily reworked by the C++ Learning Group at the OpenTechSchool Zurich to only depend on the standard library and to ease the integration in existing programs.
- Define commands with parameters and attach actions to them.
- Optionally add aliases.
- Trigger the commands.
- Get a list of all available commands.
- Get a help description for each command.
This software is distributed under the MIT License (see the License and Authors files for more details).
The simplest way to use this console, is to copy the console.h and console.cpp files in your project and build them with your code.
Example of usages can be found in the sample/ directory.
If you want to run the example, you simply have to build the project:
$ mkdir build
$ cd build
$ cmake ..
$ makeThe samples binaries are generated in build/samples/
You can also use the shared library that is generated during the build project and stored in build/lib/.
- Commands are case sensitive
- Use double quotes (
") to enclose arguments with spaces in them. - Double quotes and backslash can be escaped with a backspace (
\",\\). - If the backspace (
\) is not followed by a double quote or a backslash, it is inserted literally and so is the following character. help commandNamereturns the help string forcommandName.help commandsreturns the list of commands with their descriptions.- No direct output:
print()builds a string that can be returned to the caller.
help: an help command is automatically generated.commands: if you create acommandscommand you won't be able to get help on it.
Commands can be registered and triggered.
The engine is almost complete but has not been tested in production yet.
- A very similar project: https://github.com/RippeR37/SLACC.
I would like an or two OTS workshops to:
- Write the tests.
- Write the demo files.
- Write the documentation.
- Check if there are memory leaks.
Next steps:
- move the action on strings (tokenize, argumentConverter, evt. the case insensitive functions) to a separate "Utils" class?
- check that default values work correctly when there are multiple arguments.
- change
getUsage()to return "( name, [ i])" instead of ", []"? - get googletest to work again
- create an interactive demo program (libui? pure console?)
- check if we should bother about BOM
- allow to run a list of commands from a text file? (or is this something the using software should manage?)
- suggest similar commands if no matching found? (or should it be a different library?)
- eventually implement a "tab complete" (or should it be a different library?)
- rename the project as "CommandEngine"?
- write tests:
- add a command that already exists
- add an alias that already exists (alias, command)
- add an alias to a command that does not exist
- eventually remove the test for the text parsing, since it's a private class function