Skip to content

Commit fac033b

Browse files
committed
Document converter validation and deferred variable resolution
converters.md: - Update Boolean accepted values to include 1/0 and note rejection - Add error examples for built-in converters (integer, boolean, long) options.md: - Update variable resolution description: re-resolved on each parse cycle (#520), testable with env var changes after construction - Note env var priority over DefaultValueProvider (#521)
1 parent 6274363 commit fac033b

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

content/docs/aesh/converters.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The `ConverterInvocation` provides:
2626
- `String`
2727
- `int` / `Integer`, `long` / `Long`, `short` / `Short`, `byte` / `Byte`
2828
- `float` / `Float`, `double` / `Double`
29-
- `boolean` / `Boolean` (accepts `true`, `false`, `yes`, `no`)
29+
- `boolean` / `Boolean` (accepts `true`/`false`, `yes`/`no`, `1`/`0` — case-insensitive; rejects unrecognized values)
3030
- `char` / `Character`
3131
- `File`, `Path`, [`Resource`](../resources)
3232
- Any `Enum` type (matched by name, case-insensitive)
@@ -128,13 +128,26 @@ Timeout set to 300 seconds
128128

129129
## Error Handling
130130

131-
When conversion fails, throw `OptionValidatorException` with a message describing what went wrong and what the user should provide instead. Æsh displays the message to the user and aborts command parsing:
131+
When conversion fails, throw `OptionValidatorException` with a message describing what went wrong and what the user should provide instead. Aesh displays the message to the user and aborts command parsing:
132132

133133
```
134134
$ timeout --duration abc
135135
Invalid duration: abc. Use format like: 30s, 5m, 2h, 1d
136136
```
137137

138+
All built-in converters validate their input and throw `OptionValidatorException` with descriptive messages:
139+
140+
```
141+
$ myapp --port abc
142+
Invalid integer value: 'abc'
143+
144+
$ myapp --fresh=foobar
145+
Invalid boolean value: 'foobar'. Expected: true/false, yes/no, 1/0
146+
147+
$ myapp --size 999999999999999999999
148+
Invalid long value: '999999999999999999999'
149+
```
150+
138151
## Converter vs Validator
139152

140153
- **Converters** transform the input string into a typed value. They answer: *"What does this string mean?"*

content/docs/aesh/options.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,9 @@ private String literal;
952952
| `${a:-${b:-c}}` | Nested fallback chain | `${env:A:-${sys:B:-default}}` |
953953
| `$${...}` | Literal (no expansion) | `$${NOT_EXPANDED}` |
954954

955-
Variable resolution applies to `defaultValue` and `fallbackValue` annotation attributes. It runs at option construction time, before `DefaultValueProvider` (which runs at parse time and takes priority over static defaults).
955+
Variable resolution applies to `defaultValue` and `fallbackValue` annotation attributes. Variables are resolved initially at option construction time and **re-resolved on each parse cycle**, so environment variable changes between command invocations are picked up automatically. This makes `${env:...}` defaults fully testable — tests that set env vars after command construction will see the updated values.
956+
957+
When a `${env:...}` or `${sys:...}` variable resolves successfully, it takes priority over `DefaultValueProvider` (see [Value Resolution Chain](#value-resolution-chain)). When the variable is not set, the provider gets a chance to supply a config-based default.
956958

957959
### Combined Example
958960

0 commit comments

Comments
 (0)