https://github.com/empirical-soft/command-interface Skip to content Sign up * Why GitHub? Features - + Mobile - + Actions - + Codespaces - + Packages - + Security - + Code review - + Issues - + Integrations - + GitHub Sponsors - + Customer stories- * Team * Enterprise * Explore + Explore GitHub - Learn and contribute + Topics - + Collections - + Trending - + Learning Lab - + Open source guides - Connect with others + The ReadME Project - + Events - + Community forum - + GitHub Education - + GitHub Stars program - * Marketplace * Pricing Plans - + Compare plans - + Contact Sales - + Education - [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this organization All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} empirical-soft / command-interface Public * Notifications * Star 141 * Fork 2 * Add a command-line interface to any C++ program BSD-2-Clause License 141 stars 2 forks Star Notifications * Code * Issues 0 * Pull requests 0 * Actions * Projects 0 * Wiki * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Wiki * Security * Insights master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 1 branch 0 tags Code Latest commit @chrisaycock chrisaycock Parse trailing line terminator correctly ... ab81b2a Oct 14, 2021 Parse trailing line terminator correctly ab81b2a Git stats * 3 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .gitignore Initial commit Feb 14, 2021 LICENSE Initial commit Feb 14, 2021 README.md Can handle member functions Oct 14, 2021 command_interface.hpp Parse trailing line terminator correctly Oct 14, 2021 repl.cpp Can handle member functions Oct 14, 2021 test_ci.cpp Parse trailing line terminator correctly Oct 14, 2021 View code README.md Command Interface This header-only library makes it easy to add command evaluation to a C++ program. #include "command_interface.hpp" class Arithmetic : public CommandInterface { static int add(int x, int y) { return x + y; } int inc(int x) { return x + 1; } void register_commands() override { register_command(add, "add", "Add two numbers"); register_command(&Arithmetic::inc, "inc", "Increment a number"); } }; A command is simply a function. Just register any function with a helper string; type safety occurs automatically. We can create a simple REPL with the above interface. #include int main() { Arithmetic arithmetic; std::string text; std::cout << ">>> "; while (std::getline(std::cin, text)) { std::cout << arithmetic.eval(text) << std::endl << std::endl; std::cout << ">>> "; } return 0; } And then we have a command-line interface. >>> help add Add two numbers inc Increment a number help Show this help >>> add 3 4 7 >>> inc 21 22 >>> add 3 4 5 Error: expected 2 arguments; got 3 >>> add 3 four Error: invalid argument type at position 1; expected type i Command Interface was created for adding a way to query state in microservices, like getting the list of outstanding orders in a trading system. This library requires Boost's lexical cast and preprocessor macros. About Add a command-line interface to any C++ program Resources Readme License BSD-2-Clause License Releases No releases published Packages 0 No packages published Languages * C++ 100.0% * (c) 2021 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.