|
| 1 | +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:pub_dev/package/backend.dart'; |
| 6 | + |
| 7 | +import 'actions.dart'; |
| 8 | + |
| 9 | +final packageVersionInfo = AdminAction( |
| 10 | + name: 'package-version-info', |
| 11 | + summary: 'Gets the package version information.', |
| 12 | + description: ''' |
| 13 | +Loads and displays the package version information. |
| 14 | +''', |
| 15 | + options: { |
| 16 | + 'package': 'The package to be loaded.', |
| 17 | + 'version': 'The version to be loaded.', |
| 18 | + }, |
| 19 | + invoke: (options) async { |
| 20 | + final package = options['package']; |
| 21 | + InvalidInputException.check( |
| 22 | + package != null && package.isNotEmpty, |
| 23 | + '`package` must be given', |
| 24 | + ); |
| 25 | + |
| 26 | + final version = options['version']; |
| 27 | + InvalidInputException.check( |
| 28 | + version != null && version.isNotEmpty, |
| 29 | + '`version` must be given', |
| 30 | + ); |
| 31 | + |
| 32 | + final pv = await packageBackend.lookupPackageVersion(package!, version!); |
| 33 | + if (pv == null) { |
| 34 | + throw NotFoundException.resource('$package/$version'); |
| 35 | + } |
| 36 | + |
| 37 | + return { |
| 38 | + 'package-version': { |
| 39 | + 'package': pv.package, |
| 40 | + 'version': pv.version, |
| 41 | + 'created': pv.created?.toIso8601String(), |
| 42 | + 'isModerated': pv.isModerated, |
| 43 | + if (pv.moderatedAt != null) |
| 44 | + 'moderatedAt': pv.moderatedAt?.toIso8601String(), |
| 45 | + }, |
| 46 | + }; |
| 47 | + }, |
| 48 | +); |
0 commit comments