Query<I extends Input, O extends Output> class
abstract
A unit of work that reads and answers, and changes nothing.
The CLI counterpart of a read in modular_api. There, the split between
reading and writing is imposed by the transport — GraphQL publishes reads,
REST publishes the whole use case. A CLI has one transport, so the split has
to be declared, and this is the declaration.
A query has no preview because it has nothing to preview, and that absence
is the whole difference between it and Command. The two share no method,
so neither can be mistaken for the other by accident, and the SDK rejects
--plan and --apply on a query without the author writing a line.
Lifecycle (managed by the framework):
- Factory function builds the Query from a
CliRequest - validate — return an error string, or
nullwhen the input is valid - execute — read, and return
O - Framework formats
Othrough the active output mode
class ListCommands implements Query<ListInput, ListOutput> {
@override
final ListInput input;
ListCommands(this.input);
@override
String? validate() => null;
@override
Future<ListOutput> execute() async =>
ListOutput(Directory(input.path).listSync().map(basename).toList());
}
Constructors
- Query()
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- input → I
-
The validated input for this invocation.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
execute(
) → Future< O> - Read, and return the answer.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
validate(
) → String? -
Validate business rules on input.
Return a human-readable error string, or
nullwhen valid.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited