run method
Runs this command.
The return value is wrapped in a Future
if necessary and returned by
CommandRunner.runCommand
.
Implementation
@override
Future<void> run() async {
final rest = argResults!.rest;
if (rest.length > 1) {
printErrorAndExit('--- Too many arguments specified ---');
}
final apiKey = Platform.environment['KENALL_API_KEY'];
if (apiKey == null) {
printErrorAndExit('--- KENALL_API_KEY is not found ---');
}
final postalCode = argResults!['code'] ?? '';
if (postalCode.isEmpty) {
printErrorAndExit('--- arguments postalCode is not found ---');
}
final config = Config(apiKey: apiKey!);
final kenallClient = KenallClient(config, http.Client());
try {
final response = await kenallClient.getAddress(
GetAddressRequest(postalCode: postalCode),
);
printInfo('version: ${response.version}');
printInfo('city count: ${response.addresses.length}');
response.addresses.forEach((address) {
printInfo('address: ${address.toJson()}');
});
exit(0);
} catch (error) {
printErrorAndExit('--- $error ---');
}
}