Proof of concept (POC) for creating a command-line interface with C++.
This section provides examples for how to use the CLI (after you install it).
Yarr be the help message.
$ cpp-cli-poc --help
USAGE:
cpp-cli-poc [-h] [--version] {-a|-m|-s} arguments ...
Where:
One of:
-a, --add
finds the sum of a series, a + b + ... + n
-s, --subtract
subtracts a series of numbers, a - b - ... - n
-m, --multiply
multiplies a series of numbers, a * b * ... * n
--, --ignore_rest
Ignores the rest of the labeled arguments following this flag.
--version
Displays version information and exits.
-h, --help
Displays usage information and exits.
arguments (accepted multiple times) <args>
(required) Numbers to operate upon.
Simple proof of concept to demonstrate a command-line interface in C++.
One may add numbers...
$ cpp-cli-poc --add 1 2 3 4
10
Subtract a series of numbers from an initial value...
$ cpp-cli-poc --subtract 10 4
6
$ cpp-cli-poc --subtract 10 4 3
3
Or, multiply a series of numbers...
$ cpp-cli-poc --multiply 1 2 3 4 5
120
This project uses cmake
, cppcheck
, cpplint
, and g++
to provide consistent builds.
sudo apt update
sudo apt install cmake g++ cppcheck
sudo python -m pip install cpplint
This project uses Catch2
and includes it as a git submodule
. Please initialize the submodule before building the project.
# If you have already cloned the repo...
git submodule update --init --recursive
# If you have yet to clone this repo (and clone using SSH)...
git clone --recurse-submodules -j8 [email protected]:SpaceKatt/cpp-cli-poc.git
A script, auto-build.sh
, is provided to automate the build process.
# clean build, generate build system
./clean-build.sh
One may also save time by reusing the build system generated in
build/
, instead of running the wholeauto-build.sh
script everytime.
# reuse compiled libs and build system
./recycle-build.sh
Once the CLI builds, we may also install it using the install.sh
script.
# install CLI for global bash use (requires sudo)
./install.sh
Catch2
and CTest
are used for testing this project. The aforementioned build script will also build tests if passed the -t
flag.
# run tests, after clean build and generating build system
./clean-build.sh -t
One may also save time by reusing the build system generated in
build/
, instead of running the wholeauto-build.sh
script everytime.
# compile and run tests and reuse compiled libs and build system
./recycle-build.sh -t
NOTE:
./recycle-build.sh -t
will fail if./clean-build.sh
is first called without the-t
flag.
cppcheck
is used for linting the project. A script, ./lint.sh
, is provided for ease of use.
# lint project, show warnings, exit 0
./lint.sh
# lint project, exit in error (1) on warnings
./lint.sh -e