Summary
In this chapter, we discussed various issues that one might encounter when building a command-line interface for an application. The most important part is parsing options and positional arguments provided by the user, implemented here using the Boost program options library. This library parses the argv array passed to the application, the environment variables, and configuration files (although we don’t use this functionality here). We also covered setting up logging (using the spdlog library), error handling, signal handling, and formatting the results to be printed to the terminal, or otherwise.
There are many ways to design a command-line interface, and there is a lot that can be done using such an interface. It is important that you have a sensible, predictable, and functional interface even if you are the only one who will use it. The addition of help and usage information will be invaluable and save vast amounts of time if you forget what options are needed...