https://github.com/spiffgreen/cli-master
A command line utility library that simplifies the development of command line apps. Made for flexibility and simplicity.
https://github.com/spiffgreen/cli-master
cli commandline cplusplus cpp cpp-library
Last synced: 6 months ago
JSON representation
A command line utility library that simplifies the development of command line apps. Made for flexibility and simplicity.
- Host: GitHub
- URL: https://github.com/spiffgreen/cli-master
- Owner: SpiffGreen
- License: mit
- Created: 2021-08-09T11:19:30.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-08-18T14:09:25.000Z (over 4 years ago)
- Last Synced: 2025-02-22T11:44:03.748Z (about 1 year ago)
- Topics: cli, commandline, cplusplus, cpp, cpp-library
- Language: C++
- Homepage:
- Size: 10.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Cli-Master
A command line utility library that simplifies the development of command line apps. Made for flexibility and simplicity.
### Installation
Simply download and place the Cli_Master.h file in the c++ compiler include directory or in your project folder
The file can be gotten [Here](./climaster.h). The [climaster.h](./climaster.h) also requires a file for some simple function, [util.h](./util.h).
### Development
This project was tested with a MinGW C++ compiler. Included in this repository is a build and run [script](./build_and_run.sh) to ease development process.
`How to use the build script`
* Simple run the script but pass the name of the file without extension.
```sh
# source file name -> main.cpp
$ ./build_and_run.sh main
```
This will generate a main.exe file and run it. If an error occurs during the compile process the executable won't run.
### Requirements
This project was tested using a gcc compiler, target MinGW32.
C++11.
### Documentation
Cli-Master provides a class with some useful functions.
* `description` This function sets the description for your program. It accepts only one parameter: ```string```
* `version` This method like the description method sets the version of your program
* `option` This method is dedicated to adding flags your command-line program will accept. It accepts three parameters all ```string```:
* `Flag` - format `", "`. Example:
`"-l, --length"`
* `Description` - A simple description of the purpose of a flag
* `defaultValue` - A default value for a flag
* `parse` This method accepts two parameters: the `no. of arguments` passed to your program from `main(int argc, char** argv)`, a pointer to the arguments. This will form the values needed by your application.
* `opts` This method takes no parameters and simply returns a `map` of flags and their values.
### Notes
* Opts will return an empty map if parse is not called before it.
* Boolean based flags will have a value of `'true'` in the opts map.
### Example
A simple command line program that expect two kinds of cli options `firstname` and `lastname`. If any other option is used the help menu is printed.
```c++
#include "Cli_Master.h"
#include
using namespace std;
int main(int argc, char** argv) {
Cli_Master program;
program.description("This is the first version of the Cli_Master C++ library for building command line apps");
program.version("v1.0.0");
program.option("-f, --firstname", "your first name", "John");
program.option("-l, --lastname", "your last name", "Doe");
program.option("-S, --save", "save generated details to file, details.txt", "true");
program.parse(argc, argv);
auto m = program.opts(); // Returns a map of the arguments with values. This map is used by the commandline-application.
if(!m.empty()) {
map::iterator itr;
for(itr = m.begin(); itr != m.end(); itr++) {
println("Key: " + itr->first + ", Value: " + itr->second);
}
}
return 0;
}
```
### Author
[Spiff Jekey-Green](https://github.com/SpiffGreen)
### License
Cli-Master is [MIT](./LICENSE) licensed