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 > 3) {
printErrorAndExit('--- Too many arguments specified ---');
}
final apiKey = Platform.environment['KENALL_API_KEY'];
if (apiKey == null) {
printErrorAndExit('--- KENALL_API_KEY is not found ---');
}
final year = argResults!['year'] ?? '';
final from = argResults!['from'] ?? '';
final to = argResults!['to'] ?? '';
final config = Config(apiKey: apiKey!);
final kenallClient = KenallClient(config, http.Client());
try {
final response = await kenallClient.getHolidays(
GetHolidaysRequest(year: year, from: from, to: to),
);
printInfo('city count: ${response.holidays.length}');
response.holidays.forEach((holiday) {
printInfo('holiday: ${holiday.toJson()}');
});
exit(0);
} catch (error) {
printErrorAndExit('--- $error ---');
}
}