@@ -38,15 +38,20 @@ public function __construct(
3838 protected function configure (): void
3939 {
4040 $ this
41+ ->addOption ('exit ' , null , InputOption::VALUE_NONE , 'Returns a non-zero exit code if any errors are encountered ' )
4142 ->addOption ('force ' , 'f ' , InputOption::VALUE_NONE , 'Force overriding of secrets that already exist in the local vault ' )
4243 ->setHelp (<<<'EOF'
4344The <info>%command.name%</info> command decrypts all secrets and copies them in the local vault.
4445
4546 <info>%command.full_name%</info>
4647
47- When the option <info>--force</info> is provided, secrets that already exist in the local vault are overriden.
48+ When the <info>--force</info> option is provided, secrets that already exist in the local vault are overriden.
4849
4950 <info>%command.full_name% --force</info>
51+
52+ When the <info>--exit</info> option is provided, the command will return a non-zero exit code if any errors are encountered.
53+
54+ <info>%command.full_name% --exit</info>
5055EOF
5156 )
5257 ;
@@ -83,16 +88,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8388 ]);
8489 }
8590
91+ $ hadErrors = false ;
8692 foreach ($ secrets as $ k => $ v ) {
8793 if (null === $ v ) {
8894 $ io ->error ($ this ->vault ->getLastMessage () ?? \sprintf ('Secret "%s" has been skipped as there was an error reading it. ' , $ k ));
95+ $ hadErrors = true ;
8996 continue ;
9097 }
9198
9299 $ this ->localVault ->seal ($ k , $ v );
93100 $ io ->note ($ this ->localVault ->getLastMessage ());
94101 }
95102
103+ if ($ hadErrors && $ input ->getOption ('exit ' )) {
104+ return 1 ;
105+ }
106+
96107 return 0 ;
97108 }
98109}
0 commit comments