@@ -38,15 +38,20 @@ public function __construct(
38
38
protected function configure (): void
39
39
{
40
40
$ this
41
+ ->addOption ('exit ' , null , InputOption::VALUE_NONE , 'Returns a non-zero exit code if any errors are encountered ' )
41
42
->addOption ('force ' , 'f ' , InputOption::VALUE_NONE , 'Force overriding of secrets that already exist in the local vault ' )
42
43
->setHelp (<<<'EOF'
43
44
The <info>%command.name%</info> command decrypts all secrets and copies them in the local vault.
44
45
45
46
<info>%command.full_name%</info>
46
47
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.
48
49
49
50
<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>
50
55
EOF
51
56
)
52
57
;
@@ -83,16 +88,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
83
88
]);
84
89
}
85
90
91
+ $ hadErrors = false ;
86
92
foreach ($ secrets as $ k => $ v ) {
87
93
if (null === $ v ) {
88
94
$ io ->error ($ this ->vault ->getLastMessage () ?? \sprintf ('Secret "%s" has been skipped as there was an error reading it. ' , $ k ));
95
+ $ hadErrors = true ;
89
96
continue ;
90
97
}
91
98
92
99
$ this ->localVault ->seal ($ k , $ v );
93
100
$ io ->note ($ this ->localVault ->getLastMessage ());
94
101
}
95
102
103
+ if ($ hadErrors && $ input ->getOption ('exit ' )) {
104
+ return 1 ;
105
+ }
106
+
96
107
return 0 ;
97
108
}
98
109
}
0 commit comments