run method

  1. @override
void run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
void run() async {
  await initializeYt();

  int? maxHeight;
  int? maxWidth;

  if (argResults?['max-height'] != null) {
    maxHeight = int.parse(argResults!['max-height']);
  }

  if (argResults?['max-width'] != null) {
    maxWidth = int.parse(argResults!['max-width']);
  }

  try {
    final videoListResponse = await videos.list(
        part: argResults!['part'],
        chart: argResults?['chart'],
        id: argResults?['id'],
        myRating: argResults?['my-rating'],
        hl: argResults?['hl'],
        maxHeight: maxHeight,
        maxResults: int.parse(argResults!['max-results']),
        maxWidth: maxWidth,
        pageToken: argResults?['page-token'],
        regionCode: argResults?['region-code'],
        videoCategoryId: argResults?['video-category-id']);

    print(videoListResponse);
  } on DioException catch (err) {
    throw UsageException('API usage error:', err.usage);
  }
}