Skip to content

Commit 5f9010d

Browse files
authored
feat: improve update prompt style (#208)
1 parent 4510785 commit 5f9010d

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

lib/src/command_runner.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class VeryGoodCommandRunner extends CommandRunner<int> {
9797
Future<int?> runCommand(ArgResults topLevelResults) async {
9898
int? exitCode = ExitCode.unavailable.code;
9999
if (topLevelResults['version'] == true) {
100-
_logger.info('very_good version: $packageVersion');
100+
_logger.info(packageVersion);
101101
exitCode = ExitCode.success.code;
102102
} else if (topLevelResults['analytics'] != null) {
103103
final optIn = topLevelResults['analytics'] == 'true';
@@ -121,7 +121,7 @@ class VeryGoodCommandRunner extends CommandRunner<int> {
121121
..info('''
122122
+------------------------------------------------------------------------------------+
123123
| |
124-
| ${lightYellow.wrap('Update available!')} ${lightCyan.wrap(packageVersion)} \u2192 ${lightCyan.wrap(latestVersion)} |
124+
| ${lightYellow.wrap('Update available!')} ${lightCyan.wrap(packageVersion)} \u2192 ${lightCyan.wrap(latestVersion)} |
125125
| ${lightYellow.wrap('Changelog:')} ${lightCyan.wrap('https://github.com/verygoodopensource/very_good_cli/releases/tag/v$latestVersion')} |
126126
| |
127127
+------------------------------------------------------------------------------------+

test/src/command_runner_test.dart

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,16 @@ const expectedUsage = [
4545
const responseBody =
4646
'{"name": "very_good_cli", "versions": ["0.4.0", "0.3.3"]}';
4747

48-
const latestVersion = '9999.0.0';
48+
const latestVersion = '0.0.0';
49+
50+
final updatePrompt = '''
51+
+------------------------------------------------------------------------------------+
52+
| |
53+
| ${lightYellow.wrap('Update available!')} ${lightCyan.wrap(packageVersion)} \u2192 ${lightCyan.wrap(latestVersion)} |
54+
| ${lightYellow.wrap('Changelog:')} ${lightCyan.wrap('https://github.com/verygoodopensource/very_good_cli/releases/tag/v$latestVersion')} |
55+
| |
56+
+------------------------------------------------------------------------------------+
57+
''';
4958

5059
void main() {
5160
group('VeryGoodCommandRunner', () {
@@ -106,18 +115,7 @@ void main() {
106115

107116
final result = await commandRunner.run(['--version']);
108117
expect(result, equals(ExitCode.success.code));
109-
verify(
110-
() => logger.info(
111-
'''
112-
+------------------------------------------------------------------------------------+
113-
| |
114-
| ${lightYellow.wrap('Update available!')} ${lightCyan.wrap(packageVersion)} \u2192 ${lightCyan.wrap(latestVersion)} |
115-
| ${lightYellow.wrap('Changelog:')} ${lightCyan.wrap('https://github.com/verygoodopensource/very_good_cli/releases/tag/v$latestVersion')} |
116-
| |
117-
+------------------------------------------------------------------------------------+
118-
''',
119-
),
120-
).called(1);
118+
verify(() => logger.info(updatePrompt)).called(1);
121119
verify(
122120
() => logger.prompt('Would you like to update? (y/n) '),
123121
).called(1);
@@ -130,11 +128,7 @@ void main() {
130128

131129
final result = await commandRunner.run(['--version']);
132130
expect(result, equals(ExitCode.success.code));
133-
verifyNever(
134-
() => logger.info(
135-
lightYellow.wrap('A new release of $packageName is available.'),
136-
),
137-
);
131+
verifyNever(() => logger.info(updatePrompt));
138132
});
139133

140134
test('updates on "y" response when newer version exists', () async {
@@ -250,7 +244,7 @@ void main() {
250244
test('outputs current version', () async {
251245
final result = await commandRunner.run(['--version']);
252246
expect(result, equals(ExitCode.success.code));
253-
verify(() => logger.info('very_good version: $packageVersion'));
247+
verify(() => logger.info(packageVersion)).called(1);
254248
});
255249
});
256250
});

0 commit comments

Comments
 (0)