Skip to content

Commit ed4e5cf

Browse files
committed
refactor: update to the latest very_good_cli template, enable completion support
1 parent 34d0c66 commit ed4e5cf

File tree

6 files changed

+257
-161
lines changed

6 files changed

+257
-161
lines changed

changelog_cli/lib/src/command_runner.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:args/args.dart';
1212
import 'package:args/command_runner.dart';
1313
import 'package:changelog_cli/src/commands/commands.dart';
1414
import 'package:changelog_cli/src/version.dart';
15+
import 'package:cli_completion/cli_completion.dart';
1516
import 'package:mason_logger/mason_logger.dart';
1617
import 'package:pub_updater/pub_updater.dart';
1718

@@ -26,7 +27,7 @@ const description = 'Command line to generate changelogs';
2627
/// $ changelog_cli --version
2728
/// ```
2829
/// {@endtemplate}
29-
class ChangelogCliCommandRunner extends CommandRunner<int> {
30+
class ChangelogCliCommandRunner extends CompletionCommandRunner<int> {
3031
/// {@macro changelog_cli_command_runner}
3132
ChangelogCliCommandRunner({
3233
Logger? logger,
@@ -88,6 +89,13 @@ class ChangelogCliCommandRunner extends CommandRunner<int> {
8889

8990
@override
9091
Future<int?> runCommand(ArgResults topLevelResults) async {
92+
// Fast track completion command
93+
if (topLevelResults.command?.name == 'completion') {
94+
await super.runCommand(topLevelResults);
95+
return ExitCode.success.code;
96+
}
97+
98+
// Verbose logs
9199
_logger
92100
..detail('Argument information:')
93101
..detail(' Top level options:');
@@ -109,16 +117,20 @@ class ChangelogCliCommandRunner extends CommandRunner<int> {
109117
}
110118
}
111119

120+
// Run the command or show version
112121
final int? exitCode;
113122
if (topLevelResults['version'] == true) {
114123
_logger.info(packageVersion);
115124
exitCode = ExitCode.success.code;
116125
} else {
117126
exitCode = await super.runCommand(topLevelResults);
118127
}
128+
129+
// Check for updates
119130
if (topLevelResults.command?.name != UpdateCommand.commandName) {
120131
await _checkForUpdates();
121132
}
133+
122134
return exitCode;
123135
}
124136

changelog_cli/lib/src/commands/update_command.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
// Copyright (c) 2022, Very Good Ventures
2-
// https://verygood.ventures
3-
//
4-
// Use of this source code is governed by an MIT-style
5-
// license that can be found in the LICENSE file or at
6-
// https://opensource.org/licenses/MIT.
1+
import 'dart:io';
72

83
import 'package:args/command_runner.dart';
94
import 'package:changelog_cli/src/command_runner.dart';
@@ -53,13 +48,25 @@ class UpdateCommand extends Command<int> {
5348
}
5449

5550
final updateProgress = _logger.progress('Updating to $latestVersion');
51+
52+
late final ProcessResult result;
5653
try {
57-
await _pubUpdater.update(packageName: packageName);
54+
result = await _pubUpdater.update(
55+
packageName: packageName,
56+
versionConstraint: latestVersion,
57+
);
5858
} catch (error) {
5959
updateProgress.fail();
6060
_logger.err('$error');
6161
return ExitCode.software.code;
6262
}
63+
64+
if (result.exitCode != ExitCode.success.code) {
65+
updateProgress.fail();
66+
_logger.err('Error updating CLI: ${result.stderr}');
67+
return ExitCode.software.code;
68+
}
69+
6370
updateProgress.complete('Updated to $latestVersion');
6471

6572
return ExitCode.success.code;

changelog_cli/lib/src/version.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

changelog_cli/pubspec.yaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
name: changelog_cli
22
description: Simple CLI to generate basic changelog for your project using conventional commits
3-
version: 0.0.6+1
3+
version: 0.1.0
44
repository: https://github.com/orestesgaolin/dart_utilities/tree/main/changelog_cli
55
screenshots:
66
- description: "Example usage of the changelog_cli"
77
path: example/screenshots/changelog_cli.png
88

99
environment:
10-
sdk: ">=2.18.0 <3.0.0"
10+
sdk: ">=3.0.0 <4.0.0"
1111

1212
dependencies:
1313
args: ^2.3.1
14+
cli_completion: ^0.5.0
1415
collection: ^1.17.0
1516
conventional_commit: ^0.6.0+1
1617
equatable: ^2.0.5
1718
file: ^7.0.1
1819
git: ^2.2.0
19-
mason_logger: ^0.2.0
20+
mason_logger: ^0.2.16
2021
pub_updater: ^0.4.0
2122

2223
dev_dependencies:
23-
build_runner: ^2.0.0
24-
build_verify: ^3.0.0
25-
build_version: ^2.0.0
24+
build_runner: ^2.4.11
25+
build_verify: ^3.1.0
26+
build_version: ^2.1.1
2627
mocktail: ^1.0.4
27-
test: ^1.19.2
28+
test: ^1.25.8
2829
very_good_analysis: ^6.0.0
2930

3031
executables:

0 commit comments

Comments
 (0)