55<h1 align =" center " >Argus</h1 >
66
77<p align =" center " >
8- <strong >Modern C library for command-line argument parsing with an elegant , declarative API</strong >
8+ <strong >Modern C library for command-line argument parsing with a powerful , declarative API</strong >
99</p >
1010
1111<p align =" center " >
12- <a href =" https://github.com/lucocozz/argus/actions/workflows/ci-complete.yml " ><img src =" https://github.com/lucocozz/argus/actions/workflows/ci-complete.yml/badge.svg " alt =" CI/CD Pipeline " ></a >
13- <a href =" https://github.com/lucocozz/argus/actions/workflows/codeql.yml " ><img src =" https://github.com/lucocozz/argus/actions/workflows/codeql.yml/badge.svg " alt =" CodeQL Analysis " ></a >
12+ <!-- < a href="https://github.com/lucocozz/argus/actions/workflows/ci-complete.yml"><img src="https://github.com/lucocozz/argus/actions/workflows/ci-complete.yml/badge.svg" alt="CI/CD Pipeline"></a>
13+ <a href="https://github.com/lucocozz/argus/actions/workflows/codeql.yml"><img src="https://github.com/lucocozz/argus/actions/workflows/codeql.yml/badge.svg" alt="CodeQL Analysis"></a> -->
1414 <a href =" https://opensource.org/licenses/MIT " ><img src =" https://img.shields.io/badge/License-MIT-blue.svg " alt =" License: MIT " ></a >
1515 <a href =" https://argus-lib.com " ><img src =" https://img.shields.io/badge/docs-latest-blue.svg " alt =" Documentation " ></a >
1616</p >
1717
1818---
1919
20- ## Why Argus?
20+ ## The Traditional Approach
2121
22- Replace tedious argument parsing with declarative definitions :
22+ Building command-line tools in C typically involves extensive boilerplate :
2323
24- getopt way - verbose and error-prone
2524``` c
26- int opt;
27- while ((opt = getopt(argc, argv, " vo:p:" )) != -1 ) {
28- switch (opt) {
29- case 'v': verbose = 1; break;
30- case 'o': output = optarg; break;
31- case 'p': port = atoi(optarg); break;
25+ #include < getopt.h>
26+ #include < stdio.h>
27+ #include < stdlib.h>
28+
29+ int main (int argc, char ** argv) {
30+ int opt, verbose = 0, port = 8080;
31+ char * output = "output.txt";
32+
33+ struct option long_options[ ] = {
34+ {"verbose", no_argument, 0, 'v'},
35+ {"output", required_argument, 0, 'o'},
36+ {"port", required_argument, 0, 'p'},
37+ {"help", no_argument, 0, 'h'},
38+ {0, 0, 0, 0}
39+ };
40+
41+ while ((opt = getopt_long(argc, argv, "vo:p: h ", long_options, NULL)) != -1) {
42+ switch (opt) {
43+ case 'v': verbose = 1; break;
44+ case 'o': output = optarg; break;
45+ case 'p':
46+ port = atoi(optarg);
47+ if (port < 1 || port > 65535) {
48+ fprintf(stderr, "Error: Port must be 1-65535\n");
49+ return 1;
50+ }
51+ break;
52+ case 'h':
53+ printf("Usage: %s [ OPTIONS] \n", argv[ 0] );
54+ printf(" -v, --verbose Enable verbose output\n");
55+ printf(" -o, --output Output file\n");
56+ printf(" -p, --port Port number\n");
57+ return 0;
58+ case '?': return 1;
59+ }
3260 }
61+
62+ // Application logic starts here...
3363}
34- // + manual validation, help generation, error handling...
3564```
3665
37- ** Argus** way - declarative and complete
66+ This approach requires manual validation, error handling, and help text generation for every application.
67+
68+ ## The Argus Approach
69+
70+ Argus eliminates this boilerplate with a declarative interface:
71+
3872```c
73+ #include <argus.h>
74+
3975ARGUS_OPTIONS(
4076 options,
4177 HELP_OPTION(),
4278 OPTION_FLAG('v', "verbose", HELP("Enable verbose output")),
43- OPTION_STRING('o', "output", HELP("Output file"), DEFAULT("result.txt")),
44- OPTION_INT('p', "port", HELP("Port number"), VALIDATOR(V_RANGE(1, 65535)))
79+ OPTION_STRING('o', "output", HELP("Output file"), DEFAULT("output.txt")),
80+ OPTION_INT('p', "port", HELP("Port number"),
81+ VALIDATOR(V_RANGE(1, 65535)), DEFAULT(8080)),
4582)
83+
84+ int main(int argc, char **argv) {
85+ argus_t argus = argus_init(options, "my_tool", "1.0.0");
86+
87+ if (argus_parse(&argus, argc, argv) != ARGUS_SUCCESS)
88+ return 1;
89+
90+ // Type-safe access to parsed values
91+ bool verbose = argus_get(&argus, "verbose").as_bool;
92+ const char *output = argus_get(&argus, "output").as_string;
93+ int port = argus_get(&argus, "port").as_int;
94+
95+ // Application logic starts here...
96+ argus_free(&argus);
97+ return 0;
98+ }
4699```
47100
101+ The result is the same functionality with significantly less code and automatic validation, help generation, and type safety.
102+
48103## Core Features
49104
50- - **🎯 Type Safety** - Strong typing with automatic validation
51- - **📖 Auto Help** - Beautiful help generation from definitions
52- - **🔧 Subcommands** - Git/Docker style nested commands
53- - **📦 Collections** - Arrays and maps for multiple values
54- - **🌍 Environment** - Seamless env var integration
55- - **✅ Validation** - Built-in validators + regex patterns
105+ - ** Type Safety** - Strong typing with automatic validation and conversion
106+ - ** Declarative API** - Define your interface once, get everything else automatically
107+ - ** Auto-generated Help** - Consistent, professional help output based on your definitions
108+ - ** Built-in Validation** - Range checking, pattern matching, and custom validators
109+ - ** Subcommands** - Git-style nested commands with inheritance
110+ - ** Environment Variables** - Seamless integration with system environment
111+ - ** Collections** - Arrays and key-value maps for complex data structures
112+ - ** Cross-platform** - Works on Linux, macOS, and Windows
56113
57114## Quick Start
58115
59- **Install :**
116+ ** Installation :**
60117``` bash
61118# Package managers
62119vcpkg install argus
63120conan install argus/0.1.0
64121
65122# From source
66- git clone https:// github.com/lucocozz/argus.git && cd argus
67- meson setup build && meson compile -C build && sudo meson install -C build
123+ git clone https://github.com/lucocozz/argus.git
124+ cd argus && meson setup build && meson compile -C build
125+ sudo meson install -C build
68126```
69127
70- ** Create your first CLI :**
128+ ** Basic Example :**
71129``` c
72130#include < argus.h>
73131
74132ARGUS_OPTIONS (
75133 options,
76134 HELP_OPTION(),
77- OPTION_FLAG('v ', "verbose ", HELP("Verbose output ")),
78- OPTION_STRING('o ', "output ", HELP("Output file"), DEFAULT("result.txt ")),
79- POSITIONAL_STRING("input ", HELP("Input file "))
135+ OPTION_STRING('f ', "file ", HELP("Input file ")),
136+ OPTION_FLAG('v ', "verbose ", HELP("Enable verbose output ")),
137+ POSITIONAL_STRING("output ", HELP("Output destination ")),
80138)
81139
82- int main(int argc, char ** argv)
83- {
84- argus_t argus = argus_init(options, "my_tool", "1.0.0");
140+ int main(int argc, char ** argv) {
141+ argus_t argus = argus_init(options, "example", "1.0.0");
85142
86143 if (argus_parse(&argus, argc, argv) != ARGUS_SUCCESS)
87144 return 1;
88145
89- // Type-safe access
90- bool verbose = argus_get(argus, "verbose").as_bool;
91- const char * input = argus_get(argus, "input").as_string;
92-
93- printf("Processing %s\n", input);
146+ // Access parsed values
147+ const char * file = argus_get(&argus, "file").as_string;
148+ bool verbose = argus_get(&argus, "verbose").as_bool;
149+ const char * output = argus_get(&argus, "output").as_string;
94150
95151 argus_free(&argus);
96152 return 0;
97153}
98154```
99155
100- **Build and test:**
101- ```bash
102- gcc my_tool.c -o my_tool -largus
103- ./my_tool --help # See auto-generated help
104- ./my_tool input.txt # Run your tool
105- ```
106-
107- ## Real-World Examples
156+ ## Advanced Features
108157
109158<details>
110- <summary ><strong >Git-like Tool </strong ></summary >
159+ <summary><strong>Complex Validation and Types </strong></summary>
111160
112161```c
113- // Subcommands with their own options
114- ARGUS_OPTIONS (add_options,
115- HELP_OPTION(),
116- OPTION_FLAG('f', "force", HELP("Force add")),
117- POSITIONAL_STRING("files", HELP("Files to add"))
118- )
162+ #include <argus.h>
163+ #include <argus/regex.h>
119164
120- ARGUS_OPTIONS(options,
121- HELP_OPTION(),
122- OPTION_FLAG('v', "verbose", HELP("Verbose output")),
123- SUBCOMMAND("add", add_options, HELP("Add files"), ACTION(add_command)),
124- SUBCOMMAND("status", status_options, HELP("Show status"), ACTION(status_command))
165+ ARGUS_OPTIONS(
166+ server_options,
167+ OPTION_STRING(
168+ 'H', "host",
169+ HELP("Server hostname"),
170+ DEFAULT("localhost"),
171+ VALIDATOR(V_REGEX(ARGUS_RE_DOMAIN))
172+ ),
173+ OPTION_INT(
174+ 'p', "port",
175+ HELP("Port number"),
176+ VALIDATOR(V_RANGE(1024, 65535)),
177+ ENV_VAR("PORT")
178+ ),
179+ OPTION_ARRAY_STRING(
180+ 'w', "worker",
181+ HELP("Worker processes"),
182+ VALIDATOR(V_COUNT(1, 8))
183+ ),
184+ POSITIONAL_MAP_STRING(
185+ "config",
186+ HELP("Key=value configuration pairs")
187+ )
125188)
126-
127- // Usage: ./vcs add --force file.txt
128- // ./vcs status --verbose
129189```
130190</details >
131191
132192<details >
133- <summary><strong>Configuration Tool </strong></summary>
193+ <summary ><strong >Subcommands </strong ></summary >
134194
135195``` c
136- ARGUS_OPTIONS(options,
137- HELP_OPTION(),
138- // Array of tags
139- OPTION_ARRAY_STRING('t', "tags", HELP("Resource tags")),
140- // Key-value environment variables
141- OPTION_MAP_STRING('e', "env", HELP("Environment variables")),
142- // Email validation with regex
143- OPTION_STRING('n', "notify", HELP("Notification email"),
144- VALIDATOR(V_REGEX(ARGUS_RE_EMAIL)))
196+ // Define subcommand options
197+ ARGUS_OPTIONS (
198+ deploy_options,
199+ OPTION_FLAG('f', "force", HELP("Force deployment")),
200+ OPTION_STRING('e', "environment", HELP("Target environment")),
145201)
146202
147- // Usage: ./config --tags=web,api --env=DEBUG=1,PORT=8080 [email protected] 148- ```
149- </details>
150-
151- <details>
152- <summary><strong>Server Application</strong></summary>
203+ ARGUS_OPTIONS(
204+ status_options,
205+ OPTION_FLAG('v', "verbose", HELP("Verbose status output")),
206+ OPTION_STRING('s', "service", HELP("Service name to check")),
207+ )
153208
154- ```c
155- ARGUS_OPTIONS(options,
209+ // Main command with subcommands
210+ ARGUS_OPTIONS(
211+ main_options,
156212 HELP_OPTION(),
157- // Load from environment with fallback
158- OPTION_STRING('H', "host", HELP("Bind address"),
159- ENV_VAR("HOST"), DEFAULT("0.0.0.0")),
160- OPTION_INT('p', "port", HELP("Port number"),
161- ENV_VAR("PORT"), VALIDATOR(V_RANGE(1, 65535)), DEFAULT(8080)),
162- // Choice validation
163- OPTION_STRING('l', "level", HELP("Log level"), DEFAULT("info"),
164- VALIDATOR(V_CHOICE_STR("debug", "info", "warn", "error")))
213+ VERSION_OPTION(),
214+ SUBCOMMAND("deploy", deploy_options, HELP("Deploy application")),
215+ SUBCOMMAND("status", status_options, HELP("Check deployment status")),
165216)
166217
167- // Usage: ./server --host 0.0.0.0 --port 8080 --level debug
168- // Or: HOST=api.example.com PORT=9000 ./server
218+ // Usage: ./app deploy --force --environment production
169219```
170220</details>
171221
172- ## Documentation
222+ ## Use Cases
173223
174- 📚 **[Full Documentation](https:// argus-lib.com)** - Complete guides and API reference
175- 🚀 **[Quick Start Guide](https:// argus-lib.com/getting-started/quickstart)** - Get running in 5 minutes
176- 💡 **[Examples](https:// argus-lib.com/examples/simple-cli)** - Real-world usage patterns
177- 🔧 **[API Reference](https:// argus-lib.com/api-reference/overview)** - Complete function and macro documentation
224+ Argus is well-suited for :
178225
179- ## Comparison
226+ - **Command-line utilities** - Tools that need robust argument handling
227+ - **Developer tools** - Build systems, code generators, deployment scripts
228+ - **System utilities** - Network tools, file processors, automation scripts
229+ - **Modern C applications** - Projects prioritizing maintainability and developer experience
180230
181- | Feature | Argus | getopt | argp | argtable3 |
182- |---------|-------|--------|------|-----------|
183- | Declarative API | ✅ | ❌ | ❌ | ❌ |
184- | Type Safety | ✅ | ❌ | ❌ | ✅ |
185- | Auto Help | ✅ | ❌ | ✅ | ✅ |
186- | Subcommands | ✅ | ❌ | ❌ | ❌ |
187- | Environment Vars | ✅ | ❌ | ❌ | ❌ |
188- | Collections | ✅ | ❌ | ❌ | ❌ |
189- | Validation | ✅ | ❌ | ❌ | ❌ |
190- | Learning Curve | Low | High | High | Medium |
231+ Consider traditional approaches for embedded systems with strict constraints, legacy codebases using getopt, or environments requiring pre-C11 compatibility.
232+
233+ ## Design Philosophy
234+
235+ **Declarative over imperative** - Describe what you need rather than how to parse it. Argus handles the implementation details.
236+
237+ **Type safety by default ** - Eliminate common parsing errors through strong typing and automatic validation.
238+
239+ **Consistency and reliability** - Generated help text is always current, validation is comprehensive, and error handling is uniform.
240+
241+ **Developer experience** - Reduce boilerplate, provide clear APIs, and make common tasks simple while keeping complex scenarios achievable.
242+
243+ ## Documentation
244+
245+ 📚 **[Complete Documentation](https:// argus-lib.com)** - Comprehensive guides and tutorials
246+ 🚀 **[Quick Start Guide](https:// argus-lib.com/getting-started/quickstart)** - Get running in minutes
247+ 💡 **[Examples](https:// argus-lib.com/examples/simple-cli)** - Real-world usage patterns
248+ 🔧 **[API Reference](https:// argus-lib.com/api-reference/overview)** - Complete function documentation
191249
192250## Requirements
193251
@@ -196,23 +254,15 @@ ARGUS_OPTIONS(options,
196254
197255## Roadmap
198256
199- - 📄 Config files - JSON/YAML configuration loading
200- - 🪶 Lightweight version - Minimal footprint option for embedded systems
201- - 🎨 Themed help - Customizable colored help output
202- - 📁 Shell completion - Auto-generated tab completion for bash/zsh/fish
203- - 🔗 Alias support - Command and option aliases for better UX
204- - 📦 Plugin system - Extensibility mechanisms for custom handlers
257+ - Configuration file support (JSON/YAML)
258+ - Shell completion generation (bash/zsh/fish)
259+ - Lightweight build option for constrained environments
260+ - Additional built-in validators and types
205261
206262## Contributing
207263
208- Contributions welcome! See [ CONTRIBUTING.md] ( CONTRIBUTING.md ) for guidelines.
264+ Contributions are welcome! Please see [ CONTRIBUTING.md] ( CONTRIBUTING.md ) for guidelines on reporting issues, submitting features, and development setup .
209265
210266## License
211267
212- MIT License - See [ LICENSE] ( LICENSE ) for details.
213-
214- ---
215-
216- <p align =" center " >
217- <sub >Built with ❤️ by <a href =" https://github.com/lucocozz " >lucocozz</a ></sub >
218- </p >
268+ MIT License - see [ LICENSE] ( LICENSE ) for details.
0 commit comments