From 2cb3c3df4099297b0a0554bb482e2de04fe86b5c Mon Sep 17 00:00:00 2001 From: sanine Date: Wed, 24 Aug 2022 00:02:17 -0500 Subject: add command-line arguments --- libs/cargs/docs/_config.yml | 6 + libs/cargs/docs/_layouts/default.html | 42 +++++ libs/cargs/docs/assets/css/default.css | 127 +++++++++++++ libs/cargs/docs/assets/css/github.css | 209 +++++++++++++++++++++ libs/cargs/docs/assets/css/monakai.css | 210 ++++++++++++++++++++++ libs/cargs/docs/assets/css/trac.css | 210 ++++++++++++++++++++++ libs/cargs/docs/assets/css/vim.css | 1 + libs/cargs/docs/assets/img/favicon.png | Bin 0 -> 1584 bytes libs/cargs/docs/assets/img/favicon.svg | 125 +++++++++++++ libs/cargs/docs/build.md | 49 +++++ libs/cargs/docs/embed.md | 47 +++++ libs/cargs/docs/index.md | 129 +++++++++++++ libs/cargs/docs/reference/cag_option_fetch.md | 32 ++++ libs/cargs/docs/reference/cag_option_get.md | 26 +++ libs/cargs/docs/reference/cag_option_get_index.md | 29 +++ libs/cargs/docs/reference/cag_option_get_value.md | 27 +++ libs/cargs/docs/reference/cag_option_prepare.md | 30 ++++ libs/cargs/docs/reference/cag_option_print.md | 28 +++ libs/cargs/docs/reference/index.md | 30 ++++ 19 files changed, 1357 insertions(+) create mode 100644 libs/cargs/docs/_config.yml create mode 100644 libs/cargs/docs/_layouts/default.html create mode 100644 libs/cargs/docs/assets/css/default.css create mode 100644 libs/cargs/docs/assets/css/github.css create mode 100644 libs/cargs/docs/assets/css/monakai.css create mode 100644 libs/cargs/docs/assets/css/trac.css create mode 100644 libs/cargs/docs/assets/css/vim.css create mode 100644 libs/cargs/docs/assets/img/favicon.png create mode 100644 libs/cargs/docs/assets/img/favicon.svg create mode 100644 libs/cargs/docs/build.md create mode 100644 libs/cargs/docs/embed.md create mode 100644 libs/cargs/docs/index.md create mode 100755 libs/cargs/docs/reference/cag_option_fetch.md create mode 100755 libs/cargs/docs/reference/cag_option_get.md create mode 100755 libs/cargs/docs/reference/cag_option_get_index.md create mode 100755 libs/cargs/docs/reference/cag_option_get_value.md create mode 100644 libs/cargs/docs/reference/cag_option_prepare.md create mode 100755 libs/cargs/docs/reference/cag_option_print.md create mode 100644 libs/cargs/docs/reference/index.md (limited to 'libs/cargs/docs') diff --git a/libs/cargs/docs/_config.yml b/libs/cargs/docs/_config.yml new file mode 100644 index 0000000..88f7fa8 --- /dev/null +++ b/libs/cargs/docs/_config.yml @@ -0,0 +1,6 @@ +defaults: + - + scope: + path: "" # an empty string here means all files in the project + values: + layout: "default" \ No newline at end of file diff --git a/libs/cargs/docs/_layouts/default.html b/libs/cargs/docs/_layouts/default.html new file mode 100644 index 0000000..e326afd --- /dev/null +++ b/libs/cargs/docs/_layouts/default.html @@ -0,0 +1,42 @@ + + + + + {{ page.title }} - cargs + + + + + + + + + + +
+
+ + +
+
+
+
+

{{ page.title }}

+ {{ content }} +
+
+ + + diff --git a/libs/cargs/docs/assets/css/default.css b/libs/cargs/docs/assets/css/default.css new file mode 100644 index 0000000..9389ca0 --- /dev/null +++ b/libs/cargs/docs/assets/css/default.css @@ -0,0 +1,127 @@ +html, +body { + height: 100%; +} + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; + margin: auto; + padding: 20px; + padding: 0; + display: flex; + flex-flow: column; + background: #fafafa; + color: #22162B; +} + +header { + text-align: right; + margin-bottom: 20px; + padding: 20px 20px; + font-family: 'Ubuntu Mono'; + background: #451F55; + color: #F8C630; + border-bottom: 10px solid #724E91; +} + +header .inner { + max-width: 800px; + margin: auto; +} + +header .logo { + float: left; + vertical-align: middle; + display: inline-block; + font-weight: bold; + font-size: 32pt; + padding: 0; + margin-left: 10px; + line-height: 50px; +} + +header nav { + line-height: 50px; +} + +header a { + padding: 10px; + text-decoration: none; + font-weight: bold; + font-size: 18pt; + overflow: auto; + color: #E54F6D;; +} + +.main { + flex: 1; +} + +footer { + text-align: center; + margin-top: 50px; + padding: 40px 20px; + font-family: 'Ubuntu Mono'; + background: #22162B; + color: #F8C630; +} + + +a { + color: #E54F6D; +} + +h1, h2 { + font-family: 'Ubuntu Mono'; + padding-bottom: 5px; + border-bottom: 1px solid rgba(255,255,255,.2); +} + +.content { + color: #49483e; + padding-top: 20px; + max-width: 800px; + margin: auto; +} + +.highlight { + padding: 10px; + margin: 0; + overflow: auto; + white-space: pre-wrap; +} + +.highlighter-rouge { + background: rgba(0,0,0,0.1); +} + +table { + border-collapse: collapse; +} + +table td, +table th { + border: 1px solid #DDDDDD; + background: #ffffff; + padding: 5px 8px; +} + +table tr:nth-child(even) td { + background: #f8f9fb; +} + +@media (max-width: 1000px) { + header { + text-align: center; + } + + header .logo { + display: block; + float: none; + margin-bottom: 10px; + } + + .content { + padding: 0 20px; + } +} diff --git a/libs/cargs/docs/assets/css/github.css b/libs/cargs/docs/assets/css/github.css new file mode 100644 index 0000000..daf76ad --- /dev/null +++ b/libs/cargs/docs/assets/css/github.css @@ -0,0 +1,209 @@ +.highlight table td { padding: 5px; } +.highlight table pre { margin: 0; } +.highlight .cm { + color: #999988; + font-style: italic; +} +.highlight .cp { + color: #999999; + font-weight: bold; +} +.highlight .c1 { + color: #999988; + font-style: italic; +} +.highlight .cs { + color: #999999; + font-weight: bold; + font-style: italic; +} +.highlight .c, .highlight .cd { + color: #999988; + font-style: italic; +} +.highlight .err { + color: #a61717; + background-color: #e3d2d2; +} +.highlight .gd { + color: #000000; + background-color: #ffdddd; +} +.highlight .ge { + color: #000000; + font-style: italic; +} +.highlight .gr { + color: #aa0000; +} +.highlight .gh { + color: #999999; +} +.highlight .gi { + color: #000000; + background-color: #ddffdd; +} +.highlight .go { + color: #888888; +} +.highlight .gp { + color: #555555; +} +.highlight .gs { + font-weight: bold; +} +.highlight .gu { + color: #aaaaaa; +} +.highlight .gt { + color: #aa0000; +} +.highlight .kc { + color: #000000; + font-weight: bold; +} +.highlight .kd { + color: #000000; + font-weight: bold; +} +.highlight .kn { + color: #000000; + font-weight: bold; +} +.highlight .kp { + color: #000000; + font-weight: bold; +} +.highlight .kr { + color: #000000; + font-weight: bold; +} +.highlight .kt { + color: #445588; + font-weight: bold; +} +.highlight .k, .highlight .kv { + color: #000000; + font-weight: bold; +} +.highlight .mf { + color: #009999; +} +.highlight .mh { + color: #009999; +} +.highlight .il { + color: #009999; +} +.highlight .mi { + color: #009999; +} +.highlight .mo { + color: #009999; +} +.highlight .m, .highlight .mb, .highlight .mx { + color: #009999; +} +.highlight .sb { + color: #d14; +} +.highlight .sc { + color: #d14; +} +.highlight .sd { + color: #d14; +} +.highlight .s2 { + color: #d14; +} +.highlight .se { + color: #d14; +} +.highlight .sh { + color: #d14; +} +.highlight .si { + color: #d14; +} +.highlight .sx { + color: #d14; +} +.highlight .sr { + color: #009926; +} +.highlight .s1 { + color: #d14; +} +.highlight .ss { + color: #990073; +} +.highlight .s { + color: #d14; +} +.highlight .na { + color: #008080; +} +.highlight .bp { + color: #999999; +} +.highlight .nb { + color: #0086B3; +} +.highlight .nc { + color: #445588; + font-weight: bold; +} +.highlight .no { + color: #008080; +} +.highlight .nd { + color: #3c5d5d; + font-weight: bold; +} +.highlight .ni { + color: #800080; +} +.highlight .ne { + color: #990000; + font-weight: bold; +} +.highlight .nf { + color: #990000; + font-weight: bold; +} +.highlight .nl { + color: #990000; + font-weight: bold; +} +.highlight .nn { + color: #555555; +} +.highlight .nt { + color: #000080; +} +.highlight .vc { + color: #008080; +} +.highlight .vg { + color: #008080; +} +.highlight .vi { + color: #008080; +} +.highlight .nv { + color: #008080; +} +.highlight .ow { + color: #000000; + font-weight: bold; +} +.highlight .o { + color: #000000; + font-weight: bold; +} +.highlight .w { + color: #bbbbbb; +} +.highlight { + background-color: #f8f8f8; +} diff --git a/libs/cargs/docs/assets/css/monakai.css b/libs/cargs/docs/assets/css/monakai.css new file mode 100644 index 0000000..667b3ec --- /dev/null +++ b/libs/cargs/docs/assets/css/monakai.css @@ -0,0 +1,210 @@ +.highlight table td { padding: 5px; } +.highlight table pre { margin: 0; } +.highlight .c, .highlight .cd { + color: #75715e; + font-style: italic; +} +.highlight .cm { + color: #75715e; + font-style: italic; +} +.highlight .c1 { + color: #75715e; + font-style: italic; +} +.highlight .cp { + color: #75715e; + font-weight: bold; +} +.highlight .cs { + color: #75715e; + font-weight: bold; + font-style: italic; +} +.highlight .err { + color: #960050; + background-color: #1e0010; +} +.highlight .gi { + color: #ffffff; + background-color: #324932; +} +.highlight .gd { + color: #ffffff; + background-color: #493131; +} +.highlight .ge { + color: #000000; + font-style: italic; +} +.highlight .gr { + color: #aa0000; +} +.highlight .gt { + color: #aa0000; +} +.highlight .gh { + color: #999999; +} +.highlight .go { + color: #888888; +} +.highlight .gp { + color: #ee7733; +} +.highlight .gs { + font-weight: bold; +} +.highlight .gu { + color: #aaaaaa; +} +.highlight .k, .highlight .kv { + color: #66d9ef; + font-weight: bold; +} +.highlight .kc { + color: #66d9ef; + font-weight: bold; +} +.highlight .kd { + color: #66d9ef; + font-weight: bold; +} +.highlight .kp { + color: #66d9ef; + font-weight: bold; +} +.highlight .kr { + color: #66d9ef; + font-weight: bold; +} +.highlight .kt { + color: #66d9ef; + font-weight: bold; +} +.highlight .kn { + color: #f92672; + font-weight: bold; +} +.highlight .ow { + color: #f92672; + font-weight: bold; +} +.highlight .o { + color: #f92672; + font-weight: bold; +} +.highlight .mf { + color: #ae81ff; +} +.highlight .mh { + color: #ae81ff; +} +.highlight .il { + color: #ae81ff; +} +.highlight .mi { + color: #ae81ff; +} +.highlight .mo { + color: #ae81ff; +} +.highlight .m, .highlight .mb, .highlight .mx { + color: #ae81ff; +} +.highlight .se { + color: #ae81ff; +} +.highlight .sb { + color: #e6db74; +} +.highlight .sc { + color: #e6db74; +} +.highlight .sd { + color: #e6db74; +} +.highlight .s2 { + color: #e6db74; +} +.highlight .sh { + color: #e6db74; +} +.highlight .si { + color: #e6db74; +} +.highlight .sx { + color: #e6db74; +} +.highlight .sr { + color: #e6db74; +} +.highlight .s1 { + color: #e6db74; +} +.highlight .ss { + color: #e6db74; +} +.highlight .s { + color: #e6db74; +} +.highlight .na { + color: #a6e22e; +} +.highlight .nc { + color: #a6e22e; + font-weight: bold; +} +.highlight .nd { + color: #a6e22e; + font-weight: bold; +} +.highlight .ne { + color: #a6e22e; + font-weight: bold; +} +.highlight .nf { + color: #a6e22e; + font-weight: bold; +} +.highlight .no { + color: #66d9ef; +} +.highlight .bp { + color: #f8f8f2; +} +.highlight .nb { + color: #f8f8f2; +} +.highlight .ni { + color: #f8f8f2; +} +.highlight .nn { + color: #f8f8f2; +} +.highlight .vc { + color: #f8f8f2; +} +.highlight .vg { + color: #f8f8f2; +} +.highlight .vi { + color: #f8f8f2; +} +.highlight .nv { + color: #f8f8f2; +} +.highlight .w { + color: #f8f8f2; +} +.highlight .nl { + color: #f8f8f2; + font-weight: bold; +} +.highlight .nt { + color: #f92672; +} +.highlight { + color: #f8f8f2; + background-color: #49483e; +} diff --git a/libs/cargs/docs/assets/css/trac.css b/libs/cargs/docs/assets/css/trac.css new file mode 100644 index 0000000..854cfb8 --- /dev/null +++ b/libs/cargs/docs/assets/css/trac.css @@ -0,0 +1,210 @@ +.highlight table td { padding: 5px; } +.highlight table pre { margin: 0; } +.highlight .c, .highlight .cd { + color: #75715e; + font-style: italic; +} +.highlight .cm { + color: #75715e; + font-style: italic; +} +.highlight .c1 { + color: #75715e; + font-style: italic; +} +.highlight .cp { + color: #75715e; + font-weight: bold; +} +.highlight .cs { + color: #75715e; + font-weight: bold; + font-style: italic; +} +.highlight .err { + color: #960050; + background-color: #1e0010; +} +.highlight .gi { + color: #ffffff; + background-color: #324932; +} +.highlight .gd { + color: #ffffff; + background-color: #493131; +} +.highlight .ge { + color: #000000; + font-style: italic; +} +.highlight .gr { + color: #aa0000; +} +.highlight .gt { + color: #aa0000; +} +.highlight .gh { + color: #999999; +} +.highlight .go { + color: #888888; +} +.highlight .gp { + color: #555555; +} +.highlight .gs { + font-weight: bold; +} +.highlight .gu { + color: #aaaaaa; +} +.highlight .k, .highlight .kv { + color: #66d9ef; + font-weight: bold; +} +.highlight .kc { + color: #66d9ef; + font-weight: bold; +} +.highlight .kd { + color: #66d9ef; + font-weight: bold; +} +.highlight .kp { + color: #66d9ef; + font-weight: bold; +} +.highlight .kr { + color: #66d9ef; + font-weight: bold; +} +.highlight .kt { + color: #66d9ef; + font-weight: bold; +} +.highlight .kn { + color: #f92672; + font-weight: bold; +} +.highlight .ow { + color: #f92672; + font-weight: bold; +} +.highlight .o { + color: #f92672; + font-weight: bold; +} +.highlight .mf { + color: #ae81ff; +} +.highlight .mh { + color: #ae81ff; +} +.highlight .il { + color: #ae81ff; +} +.highlight .mi { + color: #ae81ff; +} +.highlight .mo { + color: #ae81ff; +} +.highlight .m, .highlight .mb, .highlight .mx { + color: #ae81ff; +} +.highlight .se { + color: #ae81ff; +} +.highlight .sb { + color: #e6db74; +} +.highlight .sc { + color: #e6db74; +} +.highlight .sd { + color: #e6db74; +} +.highlight .s2 { + color: #e6db74; +} +.highlight .sh { + color: #e6db74; +} +.highlight .si { + color: #e6db74; +} +.highlight .sx { + color: #e6db74; +} +.highlight .sr { + color: #e6db74; +} +.highlight .s1 { + color: #e6db74; +} +.highlight .ss { + color: #e6db74; +} +.highlight .s { + color: #e6db74; +} +.highlight .na { + color: #a6e22e; +} +.highlight .nc { + color: #a6e22e; + font-weight: bold; +} +.highlight .nd { + color: #a6e22e; + font-weight: bold; +} +.highlight .ne { + color: #a6e22e; + font-weight: bold; +} +.highlight .nf { + color: #a6e22e; + font-weight: bold; +} +.highlight .no { + color: #66d9ef; +} +.highlight .bp { + color: #f8f8f2; +} +.highlight .nb { + color: #f8f8f2; +} +.highlight .ni { + color: #f8f8f2; +} +.highlight .nn { + color: #f8f8f2; +} +.highlight .vc { + color: #f8f8f2; +} +.highlight .vg { + color: #f8f8f2; +} +.highlight .vi { + color: #f8f8f2; +} +.highlight .nv { + color: #f8f8f2; +} +.highlight .w { + color: #f8f8f2; +} +.highlight .nl { + color: #f8f8f2; + font-weight: bold; +} +.highlight .nt { + color: #f92672; +} +.highlight { + color: #f8f8f2; + background-color: #49483e; +} diff --git a/libs/cargs/docs/assets/css/vim.css b/libs/cargs/docs/assets/css/vim.css new file mode 100644 index 0000000..75e00ef --- /dev/null +++ b/libs/cargs/docs/assets/css/vim.css @@ -0,0 +1 @@ +unknown theme: vim diff --git a/libs/cargs/docs/assets/img/favicon.png b/libs/cargs/docs/assets/img/favicon.png new file mode 100644 index 0000000..b4d46f6 Binary files /dev/null and b/libs/cargs/docs/assets/img/favicon.png differ diff --git a/libs/cargs/docs/assets/img/favicon.svg b/libs/cargs/docs/assets/img/favicon.svg new file mode 100644 index 0000000..acf0df6 --- /dev/null +++ b/libs/cargs/docs/assets/img/favicon.svg @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + C + + diff --git a/libs/cargs/docs/build.md b/libs/cargs/docs/build.md new file mode 100644 index 0000000..599c114 --- /dev/null +++ b/libs/cargs/docs/build.md @@ -0,0 +1,49 @@ +--- +title: Building +description: A guide on how to build the cargs command line arguments parser library for C/C++. +--- + +In order to build the source, you will have to download it. You can do so using git (or download it from [here](https://github.com/likle/cargs/archive/stable.zip)). +```bash +git clone -b stable git@github.com:likle/cargs.git +``` + +**Note**: The *stable* branch points to the latest stable version. You should +always use a stable version in production code. + +## Using Windows +Visual Studio 2017 is recommended, then you can just open the source using ``File -> Open -> CMake...``. You can use Visual Studio to compile the source and debug the code. Make sure you have the CMake and C/C++ features enabled. + +## Using Ubuntu +You will need [CMake](https://cmake.org/download/) and either gcc or clang installed. On Ubuntu you can use the following to compile **cargs**: +```bash +sudo apt-get install build-essential cmake +mkdir cargs/build +cd cargs/build +cmake .. +make +``` + +## Using MacOS +You will need [CMake](https://cmake.org/download/) and either gcc or clang installed. On MacOS you can use the following to compile **cargs**: +``` +brew install cmake gcc +mkdir cargs/build +cd cargs/build +cmake .. +make +``` +# Running Tests +After building **cargs** you can run tests to ensure everything is fine. In order to do that, make sure that you are in the build folder and then execute the test program: + +```bash +./cargstest +``` + +That's it! + +You can even specify which tests to execute by optionally specifying the category and test name: +```bash +# ./cargstest [category] [test] +./cargstest option complex +``` diff --git a/libs/cargs/docs/embed.md b/libs/cargs/docs/embed.md new file mode 100644 index 0000000..ed64d4e --- /dev/null +++ b/libs/cargs/docs/embed.md @@ -0,0 +1,47 @@ +--- +title: Embedding +description: A guide on how to embed the cargs command line parser library for C/C++. +--- + + +In order to embed **cargs**, you will have to download it. +You can do so using git (or download it from [here](https://github.com/likle/cargs/archive/stable.zip)). + +```bash +git clone -b stable git@github.com:likle/cargs.git +``` +**Note**: The *stable* branch points to the latest stable version. You should +always use a stable version in production code. + +## Using CMake to embed cargs +If you are using CMake it is fairly easy to embed **cargs**. +This only requires two lines, you don't even have to specify the include directories. +The following example shows how to do so: +```cmake +# Some basics you will need in your cmake file. +cmake_minimum_required(VERSION 3.9.2) +project(example C) +add_executable(example_target main.c) + +# Replace your_path_to_cargs with the path to your cargs copy. +# This could be something like "${CMAKE_CURRENT_SOURCE_DIR}/lib/cargs". +add_subdirectory(your_path_to_cargs) + +# Replace example_target with the target name which requires cargs. +# After this, there is no need to specify any include directories. +target_link_libraries(example_target cargs) +``` + +After that, you should be able to use cargs in your source code: +```c +#include +``` + +## Directly embed cargs in your source +If you don't use CMake and would like to embed **cargs** directly, you could +just add the two files ``src/cargs.c`` and ``ìnclude/cargs.h`` to your project. +The folder containing ``cargs.h`` has to be in your include directories +([Visual Studio](https://docs.microsoft.com/en-us/cpp/ide/vcpp-directories-property-page?view=vs-2017), +[Eclipse](https://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.cdt.doc.user%2Freference%2Fcdt_u_prop_general_pns_inc.htm), +[gcc](https://www.rapidtables.com/code/linux/gcc/gcc-i.html), +[clang](https://clang.llvm.org/docs/ClangCommandLineReference.html#include-path-management)). diff --git a/libs/cargs/docs/index.md b/libs/cargs/docs/index.md new file mode 100644 index 0000000..60c598e --- /dev/null +++ b/libs/cargs/docs/index.md @@ -0,0 +1,129 @@ +--- +title: C/C++ Command Line Argument Parser +description: cargs is a lightweight C/C++ command line argument parser library which can be used to parse argv and argc parameters passed to a main function. +--- + +## What is cargs? +**cargs** is a lightweight C/C++ command line argument parser library which can be used to parse argv and argc parameters passed to a main function. + +## Example +Here is a simple example of cargs in action. + ```c +#include +#include +#include + +/** + * This is the main configuration of all options available. + */ +static struct cag_option options[] = { + {.identifier = 's', + .access_letters = "s", + .access_name = NULL, + .value_name = NULL, + .description = "Simple flag"}, + + {.identifier = 'm', + .access_letters = "mMoO", + .access_name = NULL, + .value_name = NULL, + .description = "Multiple access letters"}, + + {.identifier = 'l', + .access_letters = NULL, + .access_name = "long", + .value_name = NULL, + .description = "Long parameter name"}, + + {.identifier = 'k', + .access_letters = "k", + .access_name = "key", + .value_name = "VALUE", + .description = "Parameter value"}, + + {.identifier = 'h', + .access_letters = "h", + .access_name = "help", + .description = "Shows the command help"}}; + +/** + * This is a custom project configuration structure where you can store the + * parsed information. + */ +struct demo_configuration +{ + bool simple_flag; + bool multiple_flag; + bool long_flag; + const char *key; +}; + +int main(int argc, char *argv[]) +{ + char identifier; + const char *value; + cag_option_context context; + struct demo_configuration config = {false, false, false, NULL}; + + /** + * Now we just prepare the context and iterate over all options. Simple! + */ + cag_option_prepare(&context, options, CAG_ARRAY_SIZE(options), argc, argv); + while (cag_option_fetch(&context)) { + identifier = cag_option_get(&context); + switch (identifier) { + case 's': + config.simple_flag = true; + break; + case 'm': + config.multiple_flag = true; + break; + case 'l': + config.long_flag = true; + break; + case 'k': + value = cag_option_get_value(&context); + config.key = value; + break; + case 'h': + printf("Usage: cargsdemo [OPTION]...\n"); + printf("Demonstrates the cargs library.\n\n"); + cag_option_print(options, CAG_ARRAY_SIZE(options), stdout); + printf("\nNote that all formatting is done by cargs.\n"); + return EXIT_SUCCESS; + } + } + + printf("simple_flag: %i, multiple_flag: %i, long_flag: %i, key: %s\n", + config.simple_flag, config.multiple_flag, config.long_flag, + config.key ? config.key : "-"); + + return EXIT_SUCCESS; +} + +``` + +### Example output +```console +foo@bar:~$ ./cargsdemo +simple_flag: 0, multiple_flag: 0, long_flag: 0, key: - +``` +
+```console +foo@bar:~$ ./cargsdemo -k=test -sm --long +simple_flag: 1, multiple_flag: 1, long_flag: 1, key: test +``` +
+```console +foo@bar:~$ ./cargsdemo --help +Usage: cargsdemo [OPTION]... +Demonstrates the cargs library. + + -s Simple flag + -m, -M, -o, -O Multiple access letters + --long Long parameter name + -k, --key=VALUE Parameter value + -h, --help Shows the command help + +Note that all formatting is done by cargs. +``` diff --git a/libs/cargs/docs/reference/cag_option_fetch.md b/libs/cargs/docs/reference/cag_option_fetch.md new file mode 100755 index 0000000..331ac20 --- /dev/null +++ b/libs/cargs/docs/reference/cag_option_fetch.md @@ -0,0 +1,32 @@ +--- +title: cag_option_fetch +description: Fetches an option from the argument list. +--- + +_(since v1.0.0)_ +Fetches an option from the argument list. + +## Description +```c +bool cag_option_fetch(cag_option_context *context); +``` + +This function fetches a single option from the argument list. The context +will be moved to that item. Information can be extracted from the context +after the item has been fetched. +The arguments will be re-ordered, which means that non-option arguments will +be moved to the end of the argument list. After all options have been +fetched, all non-option arguments will be positioned after the index of +the context. + +## Parameters + * **context**: The context from which we will fetch the option. + +## Return Value +Returns true if there was another option or false if the end is reached. + +## Changelog + +| Version | Description | +|------------|--------------------------------------------------------| +| **v1.0.0** | The function is introduced. | diff --git a/libs/cargs/docs/reference/cag_option_get.md b/libs/cargs/docs/reference/cag_option_get.md new file mode 100755 index 0000000..8777744 --- /dev/null +++ b/libs/cargs/docs/reference/cag_option_get.md @@ -0,0 +1,26 @@ +--- +title: cag_option_get +description: Gets the identifier of the option. +--- + +_(since v1.0.0)_ +Gets the identifier of the option. + +## Description +```c +char cag_option_get(const cag_option_context *context); +``` +This function gets the identifier of the option, which should be unique to +this option and can be used to determine what kind of option this is. + +## Parameters + * **context**: The context from which the option was fetched. + +## Return Value +Returns the identifier of the option. + +## Changelog + +| Version | Description | +|------------|--------------------------------------------------------| +| **v1.0.0** | The function is introduced. | diff --git a/libs/cargs/docs/reference/cag_option_get_index.md b/libs/cargs/docs/reference/cag_option_get_index.md new file mode 100755 index 0000000..ef27d88 --- /dev/null +++ b/libs/cargs/docs/reference/cag_option_get_index.md @@ -0,0 +1,29 @@ +--- +title: cag_option_get_index +description: Gets the current index of the context. +--- + +_(since v1.0.0)_ +Gets the current index of the context. + +## Description +```c +int cag_option_get_index(const cag_option_context *context); +``` + +This function gets the index within the argv arguments of the context. The +context always points to the next item which it will inspect. This is +particularly useful to inspect the original argument array, or to get +non-option arguments after option fetching has finished. + +## Parameters + * **context**: The context from which the option was fetched. + +## Return Value +Returns the current index of the context. + +## Changelog + +| Version | Description | +|------------|--------------------------------------------------------| +| **v1.0.0** | The function is introduced. | diff --git a/libs/cargs/docs/reference/cag_option_get_value.md b/libs/cargs/docs/reference/cag_option_get_value.md new file mode 100755 index 0000000..462e2e7 --- /dev/null +++ b/libs/cargs/docs/reference/cag_option_get_value.md @@ -0,0 +1,27 @@ +--- +title: cag_option_get_value +description: Gets the value from the option. +--- + +_(since v1.0.0)_ +Gets the value from the option. + +## Description +```c +const char *cag_option_get_value(const cag_option_context *context); +``` + +This function gets the value from the option, if any. If the option does not +contain a value, this function will return NULL. + +## Parameters + * **context**: The context from which the option was fetched. + +## Return Value +Returns a pointer to the value or NULL if there is no value. + +## Changelog + +| Version | Description | +|------------|--------------------------------------------------------| +| **v1.0.0** | The function is introduced. | diff --git a/libs/cargs/docs/reference/cag_option_prepare.md b/libs/cargs/docs/reference/cag_option_prepare.md new file mode 100644 index 0000000..c9aa9e5 --- /dev/null +++ b/libs/cargs/docs/reference/cag_option_prepare.md @@ -0,0 +1,30 @@ +--- +title: cag_option_prepare +description: Prepare argument options context for parsing. +--- + +_(since v1.0.0)_ +Prepare argument options context for parsing. + +## Description +```c +void cag_option_prepare(cag_option_context *context, const cag_option *options, + size_t option_count, int argc, char **argv); +``` + +This function prepares the context for iteration and initializes the context +with the supplied options and arguments. After the context has been prepared, +it can be used to fetch arguments from it. + +## Parameters + * **context**: The context which will be initialized. + * **options**: The registered options which are available for the program. + * **option_count**: The amount of options which are available for the program. + * **argc**: The amount of arguments the user supplied in the main function. + * **argv**: A pointer to the arguments of the main function. + +## Changelog + +| Version | Description | +|------------|--------------------------------------------------------| +| **v1.0.0** | The function is introduced. | diff --git a/libs/cargs/docs/reference/cag_option_print.md b/libs/cargs/docs/reference/cag_option_print.md new file mode 100755 index 0000000..c4531eb --- /dev/null +++ b/libs/cargs/docs/reference/cag_option_print.md @@ -0,0 +1,28 @@ +--- +title: cag_option_print +description: Prints all options to the terminal. +--- + +_(since v1.0.0)_ +description: Prints all options to the terminal. + +## Description +```c +void cag_option_print(const cag_option *options, size_t option_count, + FILE *destination); +``` + +This function prints all options to the terminal. This can be used to generate +the output for a "--help" option. + +## Parameters + * **options**: The options which will be printed. + * **option_count**: The option count which will be printed. + * **destination**: The destination where the output will be printed. + + +## Changelog + +| Version | Description | +|------------|--------------------------------------------------------| +| **v1.0.0** | The function is introduced. | diff --git a/libs/cargs/docs/reference/index.md b/libs/cargs/docs/reference/index.md new file mode 100644 index 0000000..654d9fe --- /dev/null +++ b/libs/cargs/docs/reference/index.md @@ -0,0 +1,30 @@ +--- +title: Reference +description: A complete reference of the cargs command line arguments parser library for C/C++. +--- + +## Basic +The basic functions available in cargs, which can be used to do basic command line argument parsing. + +### Functions +* **[cag_option_prepare]({{ site.baseurl }}{% link reference/cag_option_prepare.md %})** +Prepare argument options context for parsing. + +* **[cag_option_fetch]({{ site.baseurl }}{% link reference/cag_option_fetch.md %})** +Fetches an option from the argument list. + +* **[cag_option_get]({{ site.baseurl }}{% link reference/cag_option_get.md %})** + Gets the identifier of the option. + +* **[cag_option_get_value]({{ site.baseurl }}{% link reference/cag_option_get_value.md %})** +Gets the value from the option. + +* **[cag_option_get_index]({{ site.baseurl }}{% link reference/cag_option_get_index.md %})** +Gets the current index of the context. + +## Output +This section describes functions which are used to output argument information. + +### Functions +* **[cag_option_print]({{ site.baseurl }}{% link reference/cag_option_print.md %})** +Prints all options to the terminal. -- cgit v1.2.1