You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/docs/aesh/activators.md
+58-45Lines changed: 58 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,28 +5,41 @@ title: 'Activators'
5
5
weight: 11
6
6
---
7
7
8
-
Activators control whether options, arguments, or entire commands are available/enabled.
8
+
Activators control whether optionsor entire commands are available. Deactivated options are hidden from tab completion and help, and deactivated commands are invisible to the user.
9
9
10
10
## OptionActivator
11
11
12
-
Enable or disable an option based on conditions:
12
+
Enable or disable an option based on conditions. The `ParsedCommand` gives you access to the current command and the values of other options that have been parsed so far:
13
13
14
14
```java
15
+
publicinterfaceOptionActivator {
16
+
booleanisActivated(ParsedCommandparsedCommand);
17
+
}
18
+
```
19
+
20
+
### Example: Conditional Options
21
+
22
+
SSL-related options should only appear when `--secure` is used:
Copy file name to clipboardExpand all lines: content/docs/aesh/converters.md
+94-57Lines changed: 94 additions & 57 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,50 +5,105 @@ title: 'Converters'
5
5
weight: 10
6
6
---
7
7
8
-
Converters transform string input into custom types.
8
+
Converters transform the raw string input from the command line into the Java type your option or argument expects. They run automatically when Æsh populates your command object.
9
9
10
10
## Converter Interface
11
11
12
-
Implement the `Converter<T>` interface:
12
+
```java
13
+
publicinterfaceConverter<T, C extendsConverterInvocation> {
invocation.println("Timeout set to"+ duration.toSeconds() +" seconds");
64
119
returnCommandResult.SUCCESS;
65
120
}
66
121
}
67
122
```
68
123
69
-
Usage: `timeout --duration 5m`
70
-
71
-
## Built-in Converters
72
-
73
-
Æsh includes converters for common types:
74
-
-`String`
75
-
-`int`, `Integer`
76
-
-`long`, `Long`
77
-
-`float`, `Float`
78
-
-`double`, `Double`
79
-
-`boolean`, `Boolean`
80
-
-`File`
81
-
-`Path`
82
-
83
-
## Enum Conversion
124
+
```
125
+
$ timeout --duration 5m
126
+
Timeout set to 300 seconds
127
+
```
84
128
85
-
Enums are automatically converted:
129
+
## Error Handling
86
130
87
-
```java
88
-
publicenumLogLevel {
89
-
DEBUG, INFO, WARN, ERROR
90
-
}
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:
-**Converters** transform the input string into a typed value. They answer: *"What does this string mean?"*
141
+
-**Validators** check whether a value is acceptable. They answer: *"Is this value allowed?"*
105
142
106
-
Usage: `log --level DEBUG`
143
+
Converters run first. If conversion succeeds, validators run next. Use a converter when you need a custom type; use a [Validator](../validators) when the type is standard but the allowed values are restricted (e.g., port must be 1-65535).
0 commit comments