Skip to content

Commit b06c28c

Browse files
authored
feat: add uninstall command (#811)
1 parent 1fb433b commit b06c28c

File tree

5 files changed

+76
-6
lines changed

5 files changed

+76
-6
lines changed

packages/dart_frog_cli/lib/src/command_runner.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class DartFrogCommandRunner extends CompletionCommandRunner<int> {
4545
addCommand(NewCommand(logger: _logger));
4646
addCommand(ListCommand(logger: _logger));
4747
addCommand(DaemonCommand(logger: _logger));
48+
addCommand(UninstallCommand(logger: _logger));
4849
}
4950

5051
final Logger _logger;

packages/dart_frog_cli/lib/src/commands/commands.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export 'daemon/daemon.dart';
66
export 'dev/dev.dart';
77
export 'list/list.dart';
88
export 'new/new.dart';
9+
export 'uninstall/uninstall.dart';
910

1011
/// A method which returns a [Future<MasonGenerator>] given a [MasonBundle].
1112
typedef GeneratorBuilder = Future<MasonGenerator> Function(MasonBundle);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import 'package:args/command_runner.dart';
2+
import 'package:dart_frog_cli/src/command_runner.dart';
3+
import 'package:mason/mason.dart' hide packageVersion;
4+
5+
/// {@template uninstall_command}
6+
/// `dart_frog uninstall` command which explains how to uninstall
7+
/// the dart_frog_cli.
8+
/// {@endtemplate}
9+
class UninstallCommand extends Command<int> {
10+
/// {@macro uninstall_command}
11+
UninstallCommand({
12+
required Logger logger,
13+
}) : _logger = logger;
14+
15+
final Logger _logger;
16+
17+
@override
18+
String get description => 'Explains how to uninstall the Dart Frog CLI.';
19+
20+
@override
21+
String get name => 'uninstall';
22+
23+
@override
24+
Future<int> run() async {
25+
final docs = link(
26+
uri: Uri.parse('https://dartfrog.vgv.dev/docs/overview#uninstalling-'),
27+
);
28+
_logger.info(
29+
'For instructions on how to uninstall $packageName completely, check out:'
30+
'\n$docs',
31+
);
32+
33+
return ExitCode.success.code;
34+
}
35+
}

packages/dart_frog_cli/test/src/command_runner_test.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ const expectedUsage = [
2828
' --verbose Output additional logs.\n'
2929
'\n'
3030
'Available commands:\n'
31-
' build Create a production build.\n'
32-
' create Creates a new Dart Frog app.\n'
33-
' dev Run a local development server.\n'
34-
' list Lists the routes on a Dart Frog project.\n'
35-
' new Create a new route or middleware for dart_frog\n'
36-
' update Update the Dart Frog CLI.\n'
31+
' build Create a production build.\n'
32+
' create Creates a new Dart Frog app.\n'
33+
' dev Run a local development server.\n'
34+
' list Lists the routes on a Dart Frog project.\n'
35+
' new Create a new route or middleware for dart_frog\n'
36+
' uninstall Explains how to uninstall the Dart Frog CLI.\n'
37+
' update Update the Dart Frog CLI.\n'
3738
'\n'
3839
'Run "dart_frog help <command>" for more information about a command.'
3940
];
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import 'package:dart_frog_cli/src/command_runner.dart';
2+
import 'package:dart_frog_cli/src/commands/uninstall/uninstall.dart';
3+
import 'package:mason/mason.dart' hide packageVersion;
4+
import 'package:mocktail/mocktail.dart';
5+
import 'package:test/test.dart';
6+
7+
class _MockLogger extends Mock implements Logger {}
8+
9+
void main() {
10+
group('dart_frog uninstall', () {
11+
late Logger logger;
12+
late UninstallCommand command;
13+
14+
setUp(() {
15+
logger = _MockLogger();
16+
command = UninstallCommand(logger: logger);
17+
});
18+
19+
test('prints a link to the documentation section', () async {
20+
final result = await command.run();
21+
final docs = link(
22+
uri: Uri.parse('https://dartfrog.vgv.dev/docs/overview#uninstalling-'),
23+
);
24+
final message =
25+
'For instructions on how to uninstall $packageName completely, '
26+
'check out:\n$docs';
27+
28+
expect(result, equals(ExitCode.success.code));
29+
verify(() => logger.info(message)).called(1);
30+
});
31+
});
32+
}

0 commit comments

Comments
 (0)