Skip to content

Commit e6295d2

Browse files
authored
Merge pull request #65 from lucocozz/fix/64-is-set-default
[Fix] DEFAULT() no longer marks an option as set
2 parents 73e3ceb + d90f3ac commit e6295d2

12 files changed

Lines changed: 190 additions & 20 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ reports/
6262
packaging/conan/test_package/build/
6363
packaging/conan/test_package/CMakeUserPresets.json
6464
.claude/
65+
.serena/
6566
*.pyc
6667
.mypy_cache
6768
subprojects/packagecache/

‎CHANGELOG.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

1010

11+
## [0.3.0] - 2026-09-20
12+
13+
### Fixed
14+
- `DEFAULT()` no longer marks an option as set, so `argus_is_set()` reports only what the user
15+
actually provided on the command line or through the environment (#64). This also repairs three
16+
behaviours that depended on the same flag:
17+
- environment variables now override default values, restoring the documented precedence
18+
(command line > environment > default);
19+
- two options carrying a default in the same `FLAG_EXCLUSIVE` group no longer conflict;
20+
- `CONFLICT()` no longer fires against an option that merely has a default.
21+
22+
### Changed
23+
- **Breaking:** `argus_is_set()` returns `false` for an option left at its default value. Code
24+
relying on the previous behaviour should test the value itself, or invert the condition.
25+
26+
1127
## [0.2.1] - 2026-05-13
1228

1329
### Fixed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ The result is the same functionality with significantly less code and automatic
117117
```bash
118118
# Package managers
119119
vcpkg install argus
120-
conan install argus/0.2.1
120+
conan install argus/0.3.0
121121

122122
# From source
123123
git clone https://github.com/lucocozz/argus.git

‎docs/docs/getting-started/installation.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ vcpkg install argus
3131
3232
```bash
3333
# With Regex support (requires PCRE2)
34-
conan install argus/0.2.1 -o argus:regex=True
34+
conan install argus/0.3.0 -o argus:regex=True
3535
# Without Regex support (default)
36-
conan install argus/0.2.1
36+
conan install argus/0.3.0
3737
```
3838
3939
</TabItem> -->
@@ -97,9 +97,9 @@ vcpkg install argus
9797
9898
```bash
9999
# With Regex support (requires PCRE2)
100-
conan install argus/0.2.1 -o argus:regex=True
100+
conan install argus/0.3.0 -o argus:regex=True
101101
# Without Regex support (default)
102-
conan install argus/0.2.1
102+
conan install argus/0.3.0
103103
```
104104
105105
</TabItem> -->
@@ -170,9 +170,9 @@ vcpkg install argus
170170
171171
```bash
172172
# With Regex support (requires PCRE2)
173-
conan install argus/0.2.1 -o argus:regex=True
173+
conan install argus/0.3.0 -o argus:regex=True
174174
# Without Regex support (default)
175-
conan install argus/0.2.1
175+
conan install argus/0.3.0
176176
```
177177
178178
</TabItem> -->

‎includes/argus.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
/**
1919
* ARGUS_VERSION - Library version
2020
*/
21-
#define ARGUS_VERSION "0.2.1"
21+
#define ARGUS_VERSION "0.3.0"
2222

2323
#endif /* ARGUS_H */

‎includes/argus/api.h‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,16 @@ ARGUS_API void argus_print_usage(argus_t *argus);
6868
ARGUS_API void argus_print_version(argus_t *argus);
6969

7070
/**
71-
* argus_is_set - Check if an option was set on the command line
71+
* argus_is_set - Check if an option was explicitly provided
7272
*
7373
* @param argus Argus context
7474
* @param option_path Option path (name or subcommand.name format)
7575
*
76-
* @return true if the option was set, false otherwise
76+
* @return true if the option was provided on the command line or through an
77+
* environment variable, false otherwise
78+
*
79+
* @note An option left at its `DEFAULT()` value is not considered set. Use this
80+
* to tell a user-provided value apart from a default one.
7781
*/
7882
ARGUS_API bool argus_is_set(argus_t *argus, const char *option_path);
7983

‎includes/argus/options.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ ARGUS_API char *format_choices_validator(validator_data_t data);
7474
#define DEFINE_NAME(lname, sname) ((lname) ? (lname) : CHAR_TO_STRING(sname))
7575
#define DEFAULT(val) .value = (argus_value_t){ .raw = (uintptr_t)(val) }, \
7676
.default_value = (argus_value_t){ .raw = (uintptr_t)(val) }, \
77-
.is_set = true, \
7877
.have_default = true
7978
#define HANDLER(fn) .handler = (argus_handler_t)(fn)
8079
#define ACTION(fn) .action = (argus_action_t)(fn)

‎meson.build‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
project(
22
'argus', 'c',
3-
version: '0.2.1',
3+
version: '0.3.0',
44
license: 'MIT',
55
default_options: [
66
'warning_level=3',

‎source/core/parsing/post_parse_validation.c‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ static int validate_required(argus_t *argus, argus_option_t *options, argus_opti
1919
if (option->require) {
2020
for (int j = 0; option->require[j] != NULL; ++j) {
2121
argus_option_t *required = find_option_by_name(options, option->require[j]);
22-
if (required && !required->is_set) {
22+
/* An option carrying a default always holds a value, so the requirement is met. */
23+
if (required && !required->is_set && !required->have_default) {
2324
ARGUS_PARSING_ERROR(argus, ARGUS_ERROR_MISSING_REQUIRED,
2425
"Required option is missing: '%s' with option '%s'",
2526
option->require[j], option->name);
@@ -89,6 +90,14 @@ static int validate_options_set(argus_t *argus, argus_option_t *options)
8990
return (ARGUS_ERROR_MISSING_REQUIRED);
9091
}
9192

93+
/* Validators run on any option holding a value, default included. */
94+
if (option->is_set || option->have_default) {
95+
int status = call_validators(argus, option);
96+
if (status != ARGUS_SUCCESS)
97+
return (status);
98+
}
99+
100+
/* Group exclusivity and dependencies only concern what the user provided. */
92101
if (option->is_set) {
93102
int status;
94103

@@ -103,10 +112,6 @@ static int validate_options_set(argus_t *argus, argus_option_t *options)
103112
}
104113
}
105114

106-
status = call_validators(argus, option);
107-
if (status != ARGUS_SUCCESS)
108-
return (status);
109-
110115
status = validate_required(argus, options, option);
111116
if (status != ARGUS_SUCCESS)
112117
return (status);

‎tests/fonctionnel/test_api.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ Test(api, argus_is_set)
110110
cr_assert_eq(argus_is_set(&argus, "verbose"), true, "Verbose option should be set");
111111
cr_assert_eq(argus_is_set(&argus, "input"), true, "Input option should be set");
112112

113-
// Check options that were not set explicitly
114-
cr_assert_eq(argus_is_set(&argus, "number"), true, "Number option should be set via default");
113+
// Check options that were not set explicitly: a default is not a user-provided value
114+
cr_assert_eq(argus_is_set(&argus, "number"), false, "Number option should not be set by its default");
115115

116116
// Check non-existent option
117117
cr_assert_eq(argus_is_set(&argus, "nonexistent"), false, "Non-existent option should not be set");

0 commit comments

Comments
 (0)