Skip to content

Commit 70b841e

Browse files
committed
[Refacto] change public api funtion to use a pointer to a argus object
1 parent a20d985 commit 70b841e

40 files changed

+477
-483
lines changed

docs/docs/advanced/custom-handlers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ int main(int argc, char **argv)
116116
argus_parse(&argus, argc, argv);
117117
118118
// Access custom type
119-
endpoint_t *ep = (endpoint_t*)argus_get(argus, "endpoint").as_ptr;
119+
endpoint_t *ep = (endpoint_t*)argus_get(&argus, "endpoint").as_ptr;
120120
if (ep)
121121
printf("Connecting to %s:%d\n", ep->host, ep->port);
122122

docs/docs/advanced/custom-validators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ int max_greater_than_min_validator(argus_t *argus, void *option_ptr, validator_d
164164
const char *min_option = (const char *)data.custom;
165165

166166
int max_value = option->value.as_int;
167-
int min_value = argus_get(*argus, min_option).as_int;
167+
int min_value = argus_get(argus, min_option).as_int;
168168

169169
if (max_value <= min_value) {
170170
ARGUS_PARSING_ERROR(argus, "Max value %d must be greater than min value %d",

docs/docs/api-reference/overview.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ int main(int argc, char **argv)
265265
if (argus_parse(&argus, argc, argv) != ARGUS_SUCCESS)
266266
return 1;
267267

268-
bool verbose = argus_get(argus, "verbose").as_bool;
269-
const char *output = argus_get(argus, "output").as_string;
270-
const char *input = argus_get(argus, "input").as_string;
268+
bool verbose = argus_get(&argus, "verbose").as_bool;
269+
const char *output = argus_get(&argus, "output").as_string;
270+
const char *input = argus_get(&argus, "input").as_string;
271271

272272
// Application logic here
273273

@@ -281,8 +281,8 @@ int main(int argc, char **argv)
281281
```c
282282
int add_command(argus_t *argus, void *data)
283283
{
284-
const char *file = argus_get(*argus, "file").as_string;
285-
bool force = argus_get(*argus, "force").as_bool;
284+
const char *file = argus_get(argus, "file").as_string;
285+
bool force = argus_get(argus, "force").as_bool;
286286
// Command logic here
287287
return 0;
288288
}
@@ -306,10 +306,9 @@ int main(int argc, char **argv)
306306
if (argus_parse(&argus, argc, argv) != ARGUS_SUCCESS)
307307
return 1;
308308
309-
if (argus_has_command(argus)) {
309+
if (argus_has_command(&argus))
310310
return argus_exec(&argus, NULL);
311-
}
312-
311+
313312
argus_free(&argus);
314313
return 0;
315314
}

docs/docs/appendices/cheat-sheet.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int main(int argc, char **argv)
2020
return 1;
2121

2222
// Access values
23-
bool flag = argus_get(argus, "flag").as_bool;
23+
bool flag = argus_get(&argus, "flag").as_bool;
2424

2525
argus_free(&argus);
2626
return 0;
@@ -132,23 +132,23 @@ FLAGS(FLAG_SORTED_VALUE) // Sort map by values
132132

133133
```c
134134
// Basic access
135-
bool verbose = argus_get(argus, "verbose").as_bool;
136-
const char *output = argus_get(argus, "output").as_string;
135+
bool verbose = argus_get(&argus, "verbose").as_bool;
136+
const char *output = argus_get(&argus, "output").as_string;
137137

138138
// Check if set
139-
if (argus_is_set(argus, "output")) {
139+
if (argus_is_set(&argus, "output")) {
140140
// User provided this option
141141
}
142142

143143
// Array access
144-
size_t count = argus_count(argus, "tags");
145-
const char *first = argus_array_get(argus, "tags", 0).as_string;
144+
size_t count = argus_count(&argus, "tags");
145+
const char *first = argus_array_get(&argus, "tags", 0).as_string;
146146

147147
// Map access
148-
const char *user = argus_map_get(argus, "env", "USER").as_string;
148+
const char *user = argus_map_get(&argus, "env", "USER").as_string;
149149

150150
// Iterators
151-
argus_array_it_t it = argus_array_it(argus, "tags");
151+
argus_array_it_t it = argus_array_it(&argus, "tags");
152152
while (argus_array_next(&it)) {
153153
printf("%s\n", it.value.as_string);
154154
}
@@ -159,8 +159,8 @@ while (argus_array_next(&it)) {
159159
```c
160160
int add_action(argus_t *argus, void *data)
161161
{
162-
const char *file = argus_get(*argus, "file").as_string; // Local option
163-
bool verbose = argus_get(*argus, ".verbose").as_bool; // Global option
162+
const char *file = argus_get(argus, "file").as_string; // Local option
163+
bool verbose = argus_get(argus, ".verbose").as_bool; // Global option
164164
return 0;
165165
}
166166

@@ -178,7 +178,7 @@ ARGUS_OPTIONS(options,
178178
int main(int argc, char **argv)
179179
{
180180
// ... parse ...
181-
if (argus_has_command(argus)) {
181+
if (argus_has_command(&argus)) {
182182
return argus_exec(&argus, NULL);
183183
}
184184
}
@@ -245,7 +245,7 @@ OPTION_BASE('e', "endpoint", VALUE_TYPE_CUSTOM,
245245
HANDLER(endpoint_handler), FREE_HANDLER(endpoint_free))
246246

247247
// Access
248-
endpoint_t *ep = (endpoint_t*)argus_get(argus, "endpoint").as_ptr;
248+
endpoint_t *ep = (endpoint_t*)argus_get(&argus, "endpoint").as_ptr;
249249
```
250250
251251
## Groups

docs/docs/appendices/contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void test_option_parsing(void)
209209
char *argv[] = {"test", "--output", "file.txt"};
210210
assert(argus_parse(&argus, 3, argv) == ARGUS_SUCCESS);
211211

212-
const char *output = argus_get(argus, "output").as_string;
212+
const char *output = argus_get(&argus, "output").as_string;
213213
assert(strcmp(output, "file.txt") == 0);
214214

215215
argus_free(&argus);

docs/docs/examples/configuration-tool.md

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,46 +48,42 @@ ARGUS_OPTIONS(
4848

4949
void print_array_strings(argus_t argus, const char *name)
5050
{
51-
if (!argus_is_set(argus, name)) return;
51+
if (!argus_is_set(&argus, name)) return;
5252

5353
printf("%s:\n", name);
54-
argus_array_it_t it = argus_array_it(argus, name);
55-
while (argus_array_next(&it)) {
54+
argus_array_it_t it = argus_array_it(&argus, name);
55+
while (argus_array_next(&it))
5656
printf(" - %s\n", it.value.as_string);
57-
}
5857
}
5958

6059
void print_array_ints(argus_t argus, const char *name)
6160
{
62-
if (!argus_is_set(argus, name)) return;
61+
if (!argus_is_set(&argus, name)) return;
6362

6463
printf("%s:\n", name);
65-
argus_array_it_t it = argus_array_it(argus, name);
66-
while (argus_array_next(&it)) {
64+
argus_array_it_t it = argus_array_it(&argus, name);
65+
while (argus_array_next(&it))
6766
printf(" - %d\n", it.value.as_int);
68-
}
6967
}
7068

7169
void print_map_strings(argus_t argus, const char *name)
7270
{
73-
if (!argus_is_set(argus, name)) return;
71+
if (!argus_is_set(&argus, name)) return;
7472

7573
printf("%s:\n", name);
76-
argus_map_it_t it = argus_map_it(argus, name);
77-
while (argus_map_next(&it)) {
74+
argus_map_it_t it = argus_map_it(&argus, name);
75+
while (argus_map_next(&it))
7876
printf(" %s = %s\n", it.key, it.value.as_string);
79-
}
8077
}
8178

8279
void print_map_bools(argus_t argus, const char *name)
8380
{
84-
if (!argus_is_set(argus, name)) return;
81+
if (!argus_is_set(&argus, name)) return;
8582

8683
printf("%s:\n", name);
87-
argus_map_it_t it = argus_map_it(argus, name);
88-
while (argus_map_next(&it)) {
84+
argus_map_it_t it = argus_map_it(&argus, name);
85+
while (argus_map_next(&it))
8986
printf(" %s = %s\n", it.key, it.value.as_bool ? "true" : "false");
90-
}
9187
}
9288

9389
int main(int argc, char **argv)
@@ -100,17 +96,16 @@ int main(int argc, char **argv)
10096
return 1;
10197

10298
// Basic values
103-
const char *name = argus_get(argus, "name").as_string;
104-
const char *host = argus_get(argus, "host").as_string;
105-
int port = argus_get(argus, "port").as_int;
99+
const char *name = argus_get(&argus, "name").as_string;
100+
const char *host = argus_get(&argus, "host").as_string;
101+
int port = argus_get(&argus, "port").as_int;
106102

107103
printf("=== Service Configuration ===\n");
108104
printf("Name: %s\n", name);
109105
printf("Host: %s:%d\n", host, port);
110106

111-
if (argus_is_set(argus, "contact")) {
112-
printf("Contact: %s\n", argus_get(argus, "contact").as_string);
113-
}
107+
if (argus_is_set(&argus, "contact"))
108+
printf("Contact: %s\n", argus_get(&argus, "contact").as_string);
114109
printf("\n");
115110

116111
// Collections
@@ -121,8 +116,8 @@ int main(int argc, char **argv)
121116

122117
// Generate config file
123118
const char *output = "config.json";
124-
if (argus_is_set(argus, "output")) {
125-
output = argus_get(argus, "output").as_string;
119+
if (argus_is_set(&argus, "output")) {
120+
output = argus_get(&argus, "output").as_string;
126121
}
127122

128123
FILE *config = fopen(output, "w");
@@ -136,14 +131,14 @@ int main(int argc, char **argv)
136131
fprintf(config, " \"host\": \"%s\",\n", host);
137132
fprintf(config, " \"port\": %d", port);
138133

139-
if (argus_is_set(argus, "contact")) {
140-
fprintf(config, ",\n \"contact\": \"%s\"", argus_get(argus, "contact").as_string);
134+
if (argus_is_set(&argus, "contact")) {
135+
fprintf(config, ",\n \"contact\": \"%s\"", argus_get(&argus, "contact").as_string);
141136
}
142137

143138
// Add arrays
144-
if (argus_is_set(argus, "tags")) {
139+
if (argus_is_set(&argus, "tags")) {
145140
fprintf(config, ",\n \"tags\": [");
146-
argus_array_it_t it = argus_array_it(argus, "tags");
141+
argus_array_it_t it = argus_array_it(&argus, "tags");
147142
bool first = true;
148143
while (argus_array_next(&it)) {
149144
if (!first) fprintf(config, ", ");
@@ -153,9 +148,9 @@ int main(int argc, char **argv)
153148
fprintf(config, "]");
154149
}
155150

156-
if (argus_is_set(argus, "ports")) {
151+
if (argus_is_set(&argus, "ports")) {
157152
fprintf(config, ",\n \"ports\": [");
158-
argus_array_it_t it = argus_array_it(argus, "ports");
153+
argus_array_it_t it = argus_array_it(&argus, "ports");
159154
bool first = true;
160155
while (argus_array_next(&it)) {
161156
if (!first) fprintf(config, ", ");
@@ -166,9 +161,9 @@ int main(int argc, char **argv)
166161
}
167162

168163
// Add maps
169-
if (argus_is_set(argus, "env")) {
164+
if (argus_is_set(&argus, "env")) {
170165
fprintf(config, ",\n \"environment\": {");
171-
argus_map_it_t it = argus_map_it(argus, "env");
166+
argus_map_it_t it = argus_map_it(&argus, "env");
172167
bool first = true;
173168
while (argus_map_next(&it)) {
174169
if (!first) fprintf(config, ", ");
@@ -179,9 +174,9 @@ int main(int argc, char **argv)
179174
fprintf(config, "}");
180175
}
181176

182-
if (argus_is_set(argus, "features")) {
177+
if (argus_is_set(&argus, "features")) {
183178
fprintf(config, ",\n \"features\": {");
184-
argus_map_it_t it = argus_map_it(argus, "features");
179+
argus_map_it_t it = argus_map_it(&argus, "features");
185180
bool first = true;
186181
while (argus_map_next(&it)) {
187182
if (!first) fprintf(config, ", ");

0 commit comments

Comments
 (0)