11import 'dart:io' ;
22
3- import 'package:cli_completion/src/exceptions.dart' ;
4- import 'package:cli_completion/src/install/shell_completion_configuration.dart' ;
5- import 'package:cli_completion/src/system_shell.dart' ;
3+ import 'package:cli_completion/installer.dart' ;
64import 'package:mason_logger/mason_logger.dart' ;
75import 'package:meta/meta.dart' ;
86import 'package:path/path.dart' as path;
97
108/// {@template shell_completion_installation}
11- /// A description of a completion installation process for a specific shell.
9+ /// Manages the installation of completion scripts for the current shell.
1210///
1311/// Creation should be done via [CompletionInstallation.fromSystemShell] .
1412/// {@endtemplate}
@@ -22,7 +20,16 @@ class CompletionInstallation {
2220 required this .environment,
2321 });
2422
25- /// Creates a [CompletionInstallation] given the current [SystemShell] .
23+ /// Creates a [CompletionInstallation] given the current [systemShell] .
24+ ///
25+ /// If [systemShell] is null, it will assume that the current shell is
26+ /// unknown and [configuration] will be null.
27+ ///
28+ /// Pass [isWindowsOverride] to override the default value of
29+ /// [Platform.isWindows] .
30+ ///
31+ /// Pass [environmentOverride] to override the default value of
32+ /// [Platform.environment] .
2633 factory CompletionInstallation .fromSystemShell ({
2734 required SystemShell ? systemShell,
2835 required Logger logger,
@@ -54,11 +61,18 @@ class CompletionInstallation {
5461 /// equals to [Platform.environment] .
5562 final Map <String , String > environment;
5663
57- /// The associated [ShellCompletionConfiguration] .
64+ /// The associated [ShellCompletionConfiguration] inferred from the current
65+ /// shell. It is null if the current shell is unknown.
5866 final ShellCompletionConfiguration ? configuration;
5967
6068 /// Define the [Directory] in which the
6169 /// completion configuration files will be stored.
70+ ///
71+ /// If [isWindows] is true, it will return the directory defined by
72+ /// %LOCALAPPDATA%/DartCLICompletion
73+ ///
74+ /// If [isWindows] is false, it will return the directory defined by
75+ /// $HOME/.dart_cli_completion
6276 @visibleForTesting
6377 Directory get completionConfigDir {
6478 if (isWindows) {
@@ -72,8 +86,17 @@ class CompletionInstallation {
7286 }
7387 }
7488
75- /// Install completion configuration hooks for a [rootCommand] in the
89+ /// Install completion configuration files for a [rootCommand] in the
7690 /// current shell.
91+ ///
92+ /// It will create:
93+ /// - A completion script file in [completionConfigDir] that is named after
94+ /// the [rootCommand] and the current shell (e.g. `very_good.bash` ).
95+ /// - A config file in [completionConfigDir] that is named after the current
96+ /// shell (e.g. `bash-config.bash` ) that sources the aforementioned
97+ /// completion script file.
98+ /// - A line in the shell config file (e.g. `.bash_profile` ) that sources
99+ /// the aforementioned config file.
77100 void install (String rootCommand) {
78101 final configuration = this .configuration;
79102
@@ -95,7 +118,10 @@ class CompletionInstallation {
95118 writeToShellConfigFile (rootCommand);
96119 }
97120
98- /// Create a directory in which the completion config files shall be saved
121+ /// Create a directory in which the completion config files shall be saved.
122+ /// If the directory already exists, it will do nothing.
123+ ///
124+ /// The directory is defined by [completionConfigDir] .
99125 @visibleForTesting
100126 void createCompletionConfigDir () {
101127 final completionConfigDirPath = completionConfigDir.path;
@@ -117,6 +143,13 @@ class CompletionInstallation {
117143
118144 /// Creates a configuration file exclusively to [rootCommand] and the
119145 /// identified shell.
146+ ///
147+ /// The file will be named after the [rootCommand] and the current shell
148+ /// (e.g. `very_good.bash` ).
149+ ///
150+ /// The file will be created in [completionConfigDir] .
151+ ///
152+ /// If the file already exists, it will do nothing.
120153 @visibleForTesting
121154 void writeCompletionScriptForCommand (String rootCommand) {
122155 final configuration = this .configuration! ;
@@ -185,7 +218,7 @@ class CompletionInstallation {
185218 _resolveHome (configuration! .shellRCFile, environment);
186219
187220 /// Write a source to the completion global script in the shell configuration
188- /// file, which its location is described by the [configuration]
221+ /// file, which its location is described by the [configuration] .
189222 @visibleForTesting
190223 void writeToShellConfigFile (String rootCommand) {
191224 final configuration = this .configuration! ;
0 commit comments