Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pub upgrade command to show number of discontinued packages #2908

Merged
merged 3 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/src/solver/report.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,23 @@ class SolveReport {
}
}

/// Displays a single-line message, number of discontinued packages
/// if discontinued packages are detected.
Future<void> reportDiscontinued() async {
var numDiscontinued = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: follow the style from reportOutdated.

final discontinuedCount = result.packages.where((pkg) => ...).length;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I tried to do it using where but the method needs to async which is not possible with it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! - good point. Did not think of that. Then your solution is fine.

for (var id in _result.packages) {
if (id.source == null) continue;
final status =
await _cache.source(id.source).status(id, Duration(days: 3));
if (status.isDiscontinued) numDiscontinued++;
}
if (numDiscontinued > 1) {
log.message('$numDiscontinued packages are discontinued.');
} else if (numDiscontinued == 1) {
log.message('1 package is discontinued.');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be slightly easier to follow:

Suggested change
if (numDiscontinued > 1) {
log.message('$numDiscontinued packages are discontinued.');
} else if (numDiscontinued == 1) {
log.message('1 package is discontinued.');
}
if (numDiscontinued > 0) {
if (numDiscontinued == 1) {
log.message('1 package is discontinued.');
} else {
log.message('$numDiscontinued packages are discontinued.');
}
}

}

/// Displays a two-line message, number of outdated packages and an
/// instruction to run `pub outdated` if outdated packages are detected.
void reportOutdated() {
Expand Down
1 change: 1 addition & 0 deletions lib/src/solver/result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class SolveResult {
SolveReport(type, _sources, _root, _previousLockFile, this, cache);
report.summarize(dryRun: dryRun);
if (type == SolveType.UPGRADE) {
await report.reportDiscontinued();
sigurdm marked this conversation as resolved.
Show resolved Hide resolved
report.reportOutdated();
}
}
Expand Down