@@ -43,9 +43,6 @@ public function __construct(Filesystem $filesystem)
4343 $ this ->processRunner = new ProcessRunner ();
4444 }
4545
46- /**
47- * Override run to provide better error message for missing command
48- */
4946 public function run (InputInterface $ input , OutputInterface $ output ): int
5047 {
5148 try {
@@ -65,34 +62,27 @@ public function run(InputInterface $input, OutputInterface $output): int
6562
6663 protected function process (): int
6764 {
68- // Get command and arguments
6965 $ commandArgs = $ this ->argument ('cmd ' );
70-
71- // Validate command exists
7266 $ command = $ commandArgs [0 ];
7367 if (!$ this ->processRunner ->commandExists ($ command ) && !file_exists ($ command )) {
7468 error ("Command not found: {$ command }" );
7569 return self ::FAILURE ;
7670 }
7771
78- // Gather stage and vault
7972 $ stage = $ this ->stage ();
8073 $ vault = $ this ->vaultName ();
8174
8275 info ("🚀 Preparing environment for: " . implode (' ' , $ commandArgs ));
8376
8477 try {
85- // Build environment variables
8678 $ environment = $ this ->buildEnvironment ($ stage , $ vault );
8779
88- // Determine if we should inherit current environment
8980 $ inheritCurrent = !$ this ->option ('no-inherit ' );
9081
9182 if (!$ inheritCurrent ) {
9283 note ('Running with clean environment (secrets only) ' );
9384 }
9485
95- // Execute the command
9686 info ("📦 Executing command with injected secrets... \n" );
9787
9888 $ result = $ this ->processRunner ->run (
@@ -101,12 +91,9 @@ protected function process(): int
10191 getcwd ()
10292 );
10393
104- // Clear sensitive data from memory
10594 foreach ($ environment as $ key => $ value ) {
10695 unset($ environment [$ key ]);
10796 }
108-
109- // Return the exit code from the subprocess
11097 if (!$ result ->successful ) {
11198 error ("\n❌ Command failed with exit code: {$ result ->exitCode }" );
11299 } else {
@@ -124,80 +111,56 @@ protected function process(): int
124111 }
125112 }
126113
127- /**
128- * Build environment variables from secrets
129- */
130114 protected function buildEnvironment (string $ stage , string $ vaultSlug ): array
131115 {
132116 $ templateOption = $ this ->option ('template ' );
133117 $ inheritCurrent = !$ this ->option ('no-inherit ' );
134118
135- // Handle template-based injection
136- // Only use template if --template option is explicitly provided
137- // But only if no filters are specified (filters only work in direct mode)
138119 $ hasFilters = $ this ->option ('only ' ) || $ this ->option ('except ' );
139120
140121 if (!$ hasFilters && $ templateOption !== null ) {
141- // If template value is empty string, it means auto-discovery
142122 $ templatePath = $ templateOption === '' ? null : $ templateOption ;
143123 return $ this ->buildFromTemplate ($ templatePath , $ stage , $ vaultSlug , $ inheritCurrent );
144124 }
145125
146- // Direct secret injection (all secrets from vault)
147126 return $ this ->buildFromVault ($ stage , $ vaultSlug , $ inheritCurrent );
148127 }
149128
150- /**
151- * Build environment from template
152- */
153129 protected function buildFromTemplate (?string $ templatePath , string $ stage , string $ vaultSlug , bool $ inheritCurrent ): array
154130 {
155- // Resolve template path if empty
156131 if ($ templatePath === null ) {
157132 $ templatePath = $ this ->resolveTemplateForStage ($ stage );
158133 note ("Using template: {$ templatePath }" );
159134 }
160135
161- // Load template
162136 if (!file_exists ($ templatePath )) {
163137 throw new \InvalidArgumentException ("Template file not found: {$ templatePath }" );
164138 }
165139
166140 $ templateContent = file_get_contents ($ templatePath );
167141 $ template = new Template ($ templateContent );
168142
169- // Get referenced vaults from template
170143 $ referencedVaults = $ template ->allReferencedVaults ();
171144
172- // Load vaults
173145 $ vaults = [];
174146 if (empty ($ referencedVaults )) {
175- // No vault references in template, use specified vault
176147 $ vaults [$ vaultSlug ] = Keep::vault ($ vaultSlug , $ stage );
177148 } else {
178- // Load all referenced vaults
179149 foreach ($ referencedVaults as $ vaultRef ) {
180150 $ vaults [$ vaultRef ] = Keep::vault ($ vaultRef , $ stage );
181151 }
182152 }
183153
184- // Build environment from template
185154 return $ template ->toEnvironment ($ vaults , $ inheritCurrent );
186155 }
187156
188- /**
189- * Build environment from all vault secrets
190- */
191157 protected function buildFromVault (string $ stage , string $ vaultSlug , bool $ inheritCurrent ): array
192158 {
193159 $ vault = Keep::vault ($ vaultSlug , $ stage );
194160
195161 info ("Loading secrets from {$ vaultSlug }: {$ stage }" );
196162
197- // Fetch all secrets
198163 $ secrets = $ vault ->list ();
199-
200- // Apply filters if provided
201164 $ only = $ this ->option ('only ' );
202165 $ except = $ this ->option ('except ' );
203166
@@ -215,7 +178,6 @@ protected function buildFromVault(string $stage, string $vaultSlug, bool $inheri
215178
216179 note ("Injecting {$ secrets ->count ()} secret(s) as environment variables " );
217180
218- // Build environment
219181 return $ secrets ->toEnvironment ($ inheritCurrent );
220182 }
221183}
0 commit comments