- @override
Handles the command input.
Override this method to perform actions for this command.
Return value is the value returned to the command line operation. Return 0 for success.
Source
@override
Future<int> handle() async {
if (clientID == null) {
displayError("Option --id required.");
return 1;
}
if ((scopes?.isEmpty ?? true)) {
displayError("Option --scopes required.");
return 1;
}
var dataModel = new ManagedDataModel.fromCurrentMirrorSystem();
ManagedContext.defaultContext = new ManagedContext.standalone(dataModel, persistentStore);
var scopingClient = new AuthClient.public(
clientID, allowedScopes: scopes?.map((s) => new AuthScope(s))?.toList());
var query = new Query<ManagedClient>()
..where.id = whereEqualTo(clientID)
..values.allowedScope = scopingClient.allowedScopes?.map((s) => s.scopeString)?.join(" ");
try {
var result = await query.updateOne();
if (result == null) {
displayError("Client ID '$clientID' does not exist.");
return 1;
}
displayInfo("Success", color: CLIColor.green);
displayProgress("Client with ID '$clientID' has been updated.");
displayProgress("Updated scope: ${result.allowedScope}");
return 0;
} on QueryException catch (e) {
displayError("Updating Client Scope Failed");
displayProgress("$e");
}
return 1;
}