@@ -13,18 +13,18 @@ class ComponentsCommand extends Command
1313
1414 public function handle (): int
1515 {
16- $ component = $ this ->argument ( ' component ' );
16+ $ components = $ this ->getComponents ( );
1717
18- if (! $ component ) {
18+ if (empty ($ components )) {
19+ $ this ->warn ('No components found ' );
20+ return Command::FAILURE ;
21+ }
1922
20- $ publishableGroups = ServiceProvider::$ publishGroups ;
21- $ keys = array_keys ($ publishableGroups );
22- foreach ($ keys as $ key ) {
23- if (str_starts_with ($ key , 'backstage-components- ' )) {
24- $ components [] = str_replace ('backstage-components- ' , '' , $ key );
25- }
26- }
27- $ component = $ this ->choice ('Which component do you want to publish? ' , $ components );
23+ $ component = $ this ->argument ('component ' ) ?? $ this ->choice ('Which component do you want to publish? ' , $ components );
24+
25+ if (! in_array ($ component , $ components )) {
26+ $ this ->error ("Component {$ component } not found " );
27+ return Command::FAILURE ;
2828 }
2929
3030 $ this ->info ("Publishing component: {$ component }" );
@@ -34,4 +34,18 @@ public function handle(): int
3434
3535 return Command::SUCCESS ;
3636 }
37+
38+ private function getComponents (): array
39+ {
40+ $ components = [];
41+ $ publishableGroups = ServiceProvider::$ publishGroups ;
42+ $ keys = array_keys ($ publishableGroups );
43+ foreach ($ keys as $ key ) {
44+ if (str_starts_with ($ key , 'backstage-components- ' )) {
45+ $ components [] = str_replace ('backstage-components- ' , '' , $ key );
46+ }
47+ }
48+
49+ return $ components ;
50+ }
3751}
0 commit comments