Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/caibingcheng/tiny_cmdline
A tiny command line library for linux, written in C++11, based on `getopt_long`.
https://github.com/caibingcheng/tiny_cmdline
cmdline-linux getopt-long
Last synced: 11 days ago
JSON representation
A tiny command line library for linux, written in C++11, based on `getopt_long`.
- Host: GitHub
- URL: https://github.com/caibingcheng/tiny_cmdline
- Owner: caibingcheng
- License: mit
- Created: 2024-08-13T03:20:06.000Z (5 months ago)
- Default Branch: master
- Last Pushed: 2024-08-13T03:21:40.000Z (5 months ago)
- Last Synced: 2024-11-05T19:08:11.118Z (about 2 months ago)
- Topics: cmdline-linux, getopt-long
- Language: C++
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### tiny_cmdline
A tiny command line library for linux, written in C++11, based on `getopt_long`. It is very simple, less than 200 lines of code, users can easily costumize it.
When I want a command line library, I found that there are many choices, but they are too heavy for me. So I wrote this tiny command line library for myself.
The library was written in C++11, as I found many teams are still only supporting old compilers, so it's not a good idea to support C++ 14 or later.
### How to use
1. Include the header file `tiny_cmdline.h` in your project.
2. Use the namespace `tiny_cmdline`.
3. Create a `TinyCmdline` object.
4. Add arguments with `add_argument` method.
5. Parse the command line with `parse` method.```cpp
#include "tiny_cmdline.h"struct ParsedArgs {
std::string filename;
std::string ip;
int32_t port;
};// convert char* to std::string should be specialized
template <> struct tiny_cmdline::TinyCmdline::convert {
static std::string to(const char *optarg) { return std::string(optarg); }
};int main(int argc, char* argv[]) {
using namespace tiny_cmdline;ParsedArgs args;
TinyCmdline cmd;
cmd.add_argument("file", 'f', args.filename, "The file to be loaded.");
cmd.add_argument("ip", 'i', args.ip, "The IP address to connect to.");
cmd.add_argument("port", 'p', args.port, "The port to connect to.");
cmd.parse(argc, argv);
}
```