1313
1414abstract class BaseDeployCommand extends Command
1515{
16+ protected string $ envPrefix ;
17+
1618 protected function configure (): void
1719 {
1820 $ this
1921 ->addArgument ('vcl ' , InputArgument::REQUIRED , 'VCL file to deploy ' )
20- ->addOption ('uri ' , 'u ' , InputOption::VALUE_REQUIRED , 'URI to deploy to [required] ' )
21- ->addOption ('username ' , '' , InputOption::VALUE_REQUIRED , 'Username [required] ' )
22- ->addOption ('password ' , '' , InputOption::VALUE_REQUIRED , 'Password [required] ' )
23- ->addOption ('vcl-name ' , '' , InputOption::VALUE_REQUIRED , 'VCL name [required] ' )
24- ->addOption ('vcl-group ' , '' , InputOption::VALUE_REQUIRED , 'VCL group [required] ' )
22+ ->addOption ('uri ' , 'u ' , InputOption::VALUE_REQUIRED , 'URI to deploy to, default from env variable ' . $ this -> envPrefix . ' _URI [required] ' )
23+ ->addOption ('username ' , '' , InputOption::VALUE_REQUIRED , 'Username, default from env variable ' . $ this -> envPrefix . ' _USERNAME [required] ' )
24+ ->addOption ('password ' , '' , InputOption::VALUE_REQUIRED , 'Password, default from env variable ' . $ this -> envPrefix . ' _PASSWORD [required] ' )
25+ ->addOption ('vcl-name ' , '' , InputOption::VALUE_REQUIRED , 'VCL name, default from env variable ' . $ this -> envPrefix . ' _VCL_NAME [required] ' )
26+ ->addOption ('vcl-group ' , '' , InputOption::VALUE_REQUIRED , 'VCL group, default from env variable ' . $ this -> envPrefix . ' _VCL_GROUP [required] ' )
2527 ->addOption ('verify-tls ' , '' , InputOption::VALUE_REQUIRED , 'Specifies TLS verification, true|false|/path/to/certificate. See http://docs.guzzlephp.org/en/stable/request-options.html#verify for possible options ' , 'true ' )
2628 ;
2729 }
@@ -39,11 +41,11 @@ protected function getArgumentString(InputInterface $input, string $name): strin
3941 protected function requireStringOption (InputInterface $ input , string $ name ): string
4042 {
4143 $ option = $ input ->getOption ($ name );
42- if (!$ option ) {
43- throw new InvalidOptionException ($ name. ' is required ' );
44+ if (!$ option && ! $ option = getenv ( $ this -> envPrefix . ' _ ' . mb_strtoupper ( str_replace ( ' - ' , ' _ ' , $ name ))) ) {
45+ throw new InvalidOptionException (" You need to specify the option { $ name} or set the environment variable for it " );
4446 }
4547 if (!\is_string ($ option )) {
46- throw new InvalidOptionException ($ name. ' must be of type string but is ' .\gettype ($ option ));
48+ throw new InvalidOptionException ("{ $ name} must be of type string but is " .\gettype ($ option ));
4749 }
4850
4951 return $ option ;
0 commit comments