11
11
use Symfony \Component \Console \Input \InputArgument ;
12
12
use Symfony \Component \Console \Input \InputInterface ;
13
13
use Symfony \Component \Console \Output \OutputInterface ;
14
+ use Symfony \Component \Console \Question \ConfirmationQuestion ;
14
15
15
16
abstract class AbstractStoreCommand extends Command
16
17
{
@@ -19,8 +20,10 @@ abstract class AbstractStoreCommand extends Command
19
20
protected ?OutputInterface $ output = null ;
20
21
protected ?InputInterface $ input = null ;
21
22
22
- abstract protected function getStoreArgumentDescription (): string ;
23
23
abstract protected function getCommandName (): string ;
24
+ abstract protected function getCommandDescription (): string ;
25
+ abstract protected function getAdditionalDefinition (): array ;
26
+ abstract protected function getStoreArgumentDescription (): string ;
24
27
25
28
public function __construct (
26
29
protected State $ state ,
@@ -41,6 +44,21 @@ protected function getFullCommandName(): string
41
44
return $ this ->getCommandPrefix () . $ this ->getCommandName ();
42
45
}
43
46
47
+ /**
48
+ * @inheritDoc
49
+ */
50
+ protected function configure (): void
51
+ {
52
+ $ definition = [$ this ->getStoreArgumentDefinition ()];
53
+ $ definition = array_merge ($ definition , $ this ->getAdditionalDefinition ());
54
+
55
+ $ this ->setName ($ this ->getFullCommandName ())
56
+ ->setDescription ($ this ->getCommandDescription ())
57
+ ->setDefinition ($ definition );
58
+
59
+ parent ::configure ();
60
+ }
61
+
44
62
protected function setAreaCode (): void
45
63
{
46
64
try {
@@ -90,4 +108,21 @@ protected function decorateOperationAnnouncementMessage(string $msg, array $stor
90
108
? "<info> $ msg: " . join (", " , $ this ->storeNameFetcher ->getStoreNames ($ storeIds )) . '</info> '
91
109
: "<info> $ msg</info> " ;
92
110
}
111
+
112
+ protected function confirmOperation (string $ okMessage = '' , string $ cancelMessage = 'Operation cancelled ' ): bool
113
+ {
114
+ $ helper = $ this ->getHelper ('question ' );
115
+ $ question = new ConfirmationQuestion ('<question>Are you sure wish to proceed? (y/n)</question> ' , false );
116
+ if (!$ helper ->ask ($ this ->input , $ this ->output , $ question )) {
117
+ if ($ cancelMessage ) {
118
+ $ this ->output ->writeln ("<comment> $ cancelMessage</comment> " );
119
+ }
120
+ return false ;
121
+ }
122
+
123
+ if ($ okMessage ) {
124
+ $ this ->output ->writeln ("<comment> $ okMessage</comment> " );
125
+ }
126
+ return true ;
127
+ }
93
128
}
0 commit comments