@@ -2,55 +2,38 @@ import 'dart:io';
22
33import 'package:cli_completion/src/exceptions.dart' ;
44import 'package:cli_completion/src/install/shell_completion_configuration.dart' ;
5+ import 'package:cli_completion/src/system_shell.dart' ;
56import 'package:mason_logger/mason_logger.dart' ;
67import 'package:meta/meta.dart' ;
78import 'package:path/path.dart' as path;
89
910/// {@template shell_completion_installation}
1011/// A description of a completion installation process for a specific shell.
1112///
12- /// Creation should be done via [ShellCompletionInstallation.fromCurrentShell ] .
13+ /// Creation should be done via [CompletionInstallation.fromSystemShell ] .
1314/// {@endtemplate}
14- class ShellCompletionInstallation {
15+ class CompletionInstallation {
1516 /// {@macro shell_completion_installation}
1617 @visibleForTesting
17- ShellCompletionInstallation ({
18+ CompletionInstallation ({
1819 required this .configuration,
1920 required this .logger,
2021 required this .isWindows,
2122 required this .environment,
2223 });
2324
24- /// Identify the current shell and from there, create a
25- /// [ShellCompletionInstallation] with the proper
26- /// [ShellCompletionConfiguration] .
27- static ShellCompletionInstallation ? fromCurrentShell ({
25+ /// Creates a [CompletionInstallation] given the current [SystemShell] .
26+ factory CompletionInstallation .fromSystemShell ({
27+ required SystemShell systemShell,
2828 required Logger logger,
2929 bool ? isWindowsOverride,
3030 Map <String , String >? environmentOverride,
3131 }) {
32- final environment = environmentOverride ?? Platform .environment;
3332 final isWindows = isWindowsOverride ?? Platform .isWindows;
33+ final environment = environmentOverride ?? Platform .environment;
3434
35- // TODO(renancaraujo): this detects the "login shell", which can be
36- // different from the actual shell.
37- final envShell = environment['SHELL' ];
38- if (envShell == null || envShell.isEmpty) return null ;
39-
40- final basename = path.basename (envShell);
41-
42- final ShellCompletionConfiguration configuration;
43- if (basename == 'zsh' ) {
44- configuration = zshConfiguration;
45- } else if (RegExp (r'bash(\.exe)?$' ).hasMatch (basename)) {
46- // on windows basename can be bash.exe
47- configuration = bashConfiguration;
48- } else {
49- return null ;
50- }
51-
52- return ShellCompletionInstallation (
53- configuration: configuration,
35+ return CompletionInstallation (
36+ configuration: ShellCompletionConfiguration .fromSystemShell (systemShell),
5437 logger: logger,
5538 isWindows: isWindows,
5639 environment: environment,
@@ -85,7 +68,8 @@ class ShellCompletionInstallation {
8568 }
8669 }
8770
88- /// Perform the installation process.
71+ /// Install completion configuration hooks for a [rootCommand] in the
72+ /// current shell.
8973 void install (String rootCommand) {
9074 logger.detail (
9175 'Installing completion for the command $rootCommand '
0 commit comments