3030
3131final class ConfigCommand extends Command
3232{
33- /** @var list<string> */
34- public const ACTIONS = ['set ' , 'get ' , 'unset ' , 'reset ' , 'list ' , 'edit ' ];
35-
36- /** @var list<string> */
37- protected const WINDOWS_EDITORS = ['notepad ' ];
38-
39- /** @var list<string> */
40- protected const UNIX_EDITORS = ['editor ' , 'vim ' , 'vi ' , 'nano ' , 'pico ' , 'ed ' ];
33+ private const ACTIONS = ['set ' , 'get ' , 'unset ' , 'reset ' , 'list ' , 'edit ' ];
34+ private const UNIX_EDITORS = ['editor ' , 'vim ' , 'vi ' , 'nano ' , 'pico ' , 'ed ' ];
35+ private const WINDOWS_EDITORS = ['notepad ' ];
4136
4237 /** @noinspection ClassOverridesFieldOfSuperClassInspection */
4338 protected $ signature = 'config ' ;
@@ -53,25 +48,14 @@ public function __construct()
5348 }
5449
5550 /**
51+ * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
5652 * @throws \JsonException
5753 * @throws \Psr\Container\ContainerExceptionInterface
5854 * @throws \Psr\Container\NotFoundExceptionInterface
5955 */
6056 public function handle (ExecutableFinder $ executableFinder ): int
6157 {
62- /** @var string $file */
63- $ file = value (function () {
64- if ($ file = $ this ->option ('file ' )) {
65- return $ file ;
66- }
67-
68- if ($ this ->option ('global ' )) {
69- return ConfigManager::globalPath ();
70- }
71-
72- return ConfigManager::localPath ();
73- });
74-
58+ $ file = $ this ->configFile ();
7559 $ this ->output ->note ("The config file( $ file) is being operated. " );
7660 file_exists ($ file ) or $ this ->configManager ->putFile ($ file );
7761 $ this ->configManager ->replaceFrom ($ file );
@@ -176,6 +160,11 @@ public function schedule(Schedule $schedule): void
176160 // $schedule->command(static::class)->everyMinute();
177161 }
178162
163+ public static function hydratedActions (): string
164+ {
165+ return implode (', ' , self ::ACTIONS );
166+ }
167+
179168 /**
180169 * {@inheritDoc}
181170 *
@@ -185,7 +174,7 @@ public function schedule(Schedule $schedule): void
185174 protected function configure (): void
186175 {
187176 $ this ->setDefinition ([
188- new InputArgument ('action ' , InputArgument::REQUIRED , \sprintf ('The action(<comment>[%s]</comment>) name ' , implode ( ' , ' , self ::ACTIONS ))),
177+ new InputArgument ('action ' , InputArgument::REQUIRED , \sprintf ('The action(<comment>[%s]</comment>) name ' , self ::hydratedActions ( ))),
189178 new InputArgument ('key ' , InputArgument::OPTIONAL , 'The key of config options ' ),
190179 new InputArgument ('value ' , InputArgument::OPTIONAL , 'The value of config options ' ),
191180 new InputOption ('global ' , 'g ' , InputOption::VALUE_NONE , 'Apply to the global config file ' ),
@@ -250,4 +239,17 @@ private function valueToArg(mixed $value): string
250239
251240 return (string ) json_encode ($ value , \JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE );
252241 }
242+
243+ private function configFile (): string
244+ {
245+ if ($ file = $ this ->option ('file ' )) {
246+ return $ file ;
247+ }
248+
249+ if ($ this ->option ('global ' )) {
250+ return ConfigManager::globalPath ();
251+ }
252+
253+ return ConfigManager::localPath ();
254+ }
253255}
0 commit comments