Skip to content

Commit

Permalink
Rename RequireNoValue to ForceNoValue
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-zherikov committed Jan 8, 2025
1 parent a54b53d commit 7be774e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@
.AllowNoValue("myvalue")
```

* `RequireNoValue` is renamed to `ForceNoValue` and now accepts a value as run-time parameter, not as template parameter.

For example, replace this
```d
.RequireNoValue!"myvalue"
```
with
```d
.ForceNoValue("myvalue")
```

* Dropped support for DMD-2.099.

### Enhancements and bug fixes
Expand Down
2 changes: 1 addition & 1 deletion docs/code_snippets/arity_no_values.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import argparse;
struct T
{
@(NamedArgument.AllowNoValue(10)) int a;
@(NamedArgument.RequireNoValue!20) int b;
@(NamedArgument.ForceNoValue(20)) int b;
}

T t;
Expand Down
4 changes: 2 additions & 2 deletions docs/topics/Arity.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ Sometimes named arguments can have no values in command line. Here are two cases

- If value is optional and argument should get specific value in this case then use `AllowNoValue`.

- Argument must not have any values in command line. Use `RequireNoValue` in this case.
- If argument must not have any value in command line then use `ForceNoValue` in this case.

Both `AllowNoValue` and `RequireNoValue` accept a value that should be used when no value is provided in the command line.
Both `AllowNoValue` and `ForceNoValue` accept a value that should be used when no value is provided in the command line.
The difference between them can be seen in this example:

<code-block src="code_snippets/arity_no_values.d" lang="c++"/>
12 changes: 6 additions & 6 deletions docs/topics/reference/PositionalNamedArgument.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ struct my_command
**Signature**
```C++
AllowNoValue(alias valueToUse)(auto ref ... argument)
AllowNoValue(VALUE)(auto ref ... argument, VALUE valueToUse)
```

**Parameters**
Expand All @@ -269,15 +269,15 @@ struct my_command
}
```
### RequireNoValue
### ForceNoValue
`RequireNoValue` requires an argument to have no value in the command line. The argument is behaving like a boolean flag
but instead of `true`/`false` values, there can be either a value provided to this function or a default one (`.init`).
`ForceNoValue` forces an argument to have no value in the command line. The argument is behaving like a boolean flag
but instead of `true`/`false` values, there can be either a value provided to `ForceNoValue` or a default one (`.init`).
**Signature**
```C++
RequireNoValue(alias valueToUse)(auto ref ... argument)
ForceNoValue(VALUE)(auto ref ... argument, VALUE valueToUse)
```

**Parameters**
Expand All @@ -291,7 +291,7 @@ RequireNoValue(alias valueToUse)(auto ref ... argument)
```C++
struct my_command
{
@(NamedArgument.RequireNoValue!10)
@(NamedArgument.ForceNoValue!10)
int a;
}
```
Expand Down
8 changes: 4 additions & 4 deletions source/argparse/api/argument.d
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ auto AllowNoValue(VALUE, T)(ArgumentUDA!T uda, VALUE valueToUse)
return ActionNoValueImpl(uda,SetValue(valueToUse));
}

auto RequireNoValue(alias valueToUse, T)(ArgumentUDA!T uda)
auto ForceNoValue(VALUE, T)(ArgumentUDA!T uda, VALUE valueToUse)
{
auto desc = uda.AllowNoValue(valueToUse);
auto desc = AllowNoValue(uda, valueToUse);
desc.info.minValuesCount = 0;
desc.info.maxValuesCount = 0;
return desc;
Expand All @@ -190,8 +190,8 @@ unittest

unittest
{
auto uda = NamedArgument.RequireNoValue!"value";
assert(is(typeof(uda) : ArgumentUDA!(ValueParser!(P, R)), P, R));
auto uda = NamedArgument.ForceNoValue("value");
assert(is(typeof(uda) : ArgumentUDA!(ValueParser!(void, string))));
assert(uda.info.minValuesCount == 0);
assert(uda.info.maxValuesCount == 0);
}
Expand Down
2 changes: 1 addition & 1 deletion source/argparse/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ unittest
struct T
{
@(NamedArgument.AllowNoValue(10)) int a;
@(NamedArgument.RequireNoValue!20) int b;
@(NamedArgument.ForceNoValue(20)) int b;
}

assert(CLI!T.parseArgs!((T t) { assert(t.a == 10); return 12345; })(["-a"]) == 12345);
Expand Down

0 comments on commit 7be774e

Please sign in to comment.