File tree Expand file tree Collapse file tree 4 files changed +24
-6
lines changed
Expand file tree Collapse file tree 4 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,12 @@ public function __invoke(
3838 ): ExitCode {
3939 $ shell ??= $ this ->resolveShell ();
4040
41+ if ($ shell === null ) {
42+ $ this ->console ->error ('Could not detect shell. Please specify one using the --shell option. Possible values are: zsh, bash. ' );
43+
44+ return ExitCode::ERROR ;
45+ }
46+
4147 $ sourcePath = $ this ->getSourcePath ($ shell );
4248 $ targetDir = $ shell ->getCompletionsDirectory ();
4349 $ targetPath = $ shell ->getInstalledCompletionPath ();
@@ -81,7 +87,7 @@ public function __invoke(
8187 return ExitCode::SUCCESS ;
8288 }
8389
84- private function resolveShell (): Shell
90+ private function resolveShell (): ? Shell
8591 {
8692 $ detected = Shell::detect ();
8793
Original file line number Diff line number Diff line change @@ -33,6 +33,12 @@ public function __invoke(
3333 ): ExitCode {
3434 $ shell ??= $ this ->resolveShell ();
3535
36+ if ($ shell === null ) {
37+ $ this ->console ->error ('Could not detect shell. Please specify one using the --shell option. Possible values are: zsh, bash. ' );
38+
39+ return ExitCode::ERROR ;
40+ }
41+
3642 $ sourcePath = $ this ->getSourcePath ($ shell );
3743
3844 if (! Filesystem \is_file ($ sourcePath )) {
@@ -46,7 +52,7 @@ public function __invoke(
4652 return ExitCode::SUCCESS ;
4753 }
4854
49- private function resolveShell (): Shell
55+ private function resolveShell (): ? Shell
5056 {
5157 $ detected = Shell::detect ();
5258
Original file line number Diff line number Diff line change @@ -35,6 +35,12 @@ public function __invoke(
3535 ): ExitCode {
3636 $ shell ??= $ this ->resolveShell ();
3737
38+ if ($ shell === null ) {
39+ $ this ->console ->error ('Could not detect shell. Please specify one using the --shell option. Possible values are: zsh, bash. ' );
40+
41+ return ExitCode::ERROR ;
42+ }
43+
3844 $ targetPath = $ shell ->getInstalledCompletionPath ();
3945
4046 if (! Filesystem \is_file ($ targetPath )) {
@@ -66,7 +72,7 @@ public function __invoke(
6672 return ExitCode::SUCCESS ;
6773 }
6874
69- private function resolveShell (): Shell
75+ private function resolveShell (): ? Shell
7076 {
7177 $ detected = Shell::detect ();
7278
Original file line number Diff line number Diff line change @@ -9,18 +9,18 @@ enum Shell: string
99 case ZSH = 'zsh ' ;
1010 case BASH = 'bash ' ;
1111
12- public static function detect (): self
12+ public static function detect (): ? self
1313 {
1414 $ shell = getenv ('SHELL ' );
1515
1616 if ($ shell === false ) {
17- return self :: BASH ;
17+ return null ;
1818 }
1919
2020 return match (true ) {
2121 str_contains ($ shell , 'zsh ' ) => self ::ZSH ,
2222 str_contains ($ shell , 'bash ' ) => self ::BASH ,
23- default => self :: BASH ,
23+ default => null ,
2424 };
2525 }
2626
You can’t perform that action at this time.
0 commit comments