Skip to content

Commit 3e01a12

Browse files
committed
--value option
1 parent f557da1 commit 3e01a12

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

app/lib/admin/actions/package_discontinue.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@ Sets the `Package.isDiscontinued` and `Package.replacedBy` properties.
1717
''',
1818
options: {
1919
'package': 'The package to be discontinued.',
20+
'value': 'The value to set (defaults to true).',
2021
'replaced-by':
21-
'The Package.replacedBy field (if not set will be set to `null`).'
22+
'The Package.replacedBy field (if not set will be set to `null`).',
2223
},
2324
invoke: (options) async {
2425
final package = options['package'];
2526
InvalidInputException.check(
2627
package != null && package.isNotEmpty,
2728
'`package` must be given',
2829
);
30+
final value = options['value'] ?? 'true';
31+
InvalidInputException.checkAnyOf(value, 'value', ['true', 'false']);
32+
final valueToSet = value == 'true';
2933

3034
final p = await packageBackend.lookupPackage(package!);
3135
if (p == null) {
@@ -45,8 +49,8 @@ Sets the `Package.isDiscontinued` and `Package.replacedBy` properties.
4549
if (pkg == null) {
4650
throw NotFoundException.resource(package);
4751
}
48-
pkg.isDiscontinued = true;
49-
pkg.replacedBy = replacedBy;
52+
pkg.isDiscontinued = valueToSet;
53+
pkg.replacedBy = valueToSet ? replacedBy : null;
5054
pkg.updated = clock.now().toUtc();
5155
tx.insert(pkg);
5256
return pkg;

0 commit comments

Comments
 (0)