@@ -3,11 +3,19 @@ import path from 'path';
33import { getFS } from '../utils/ifs' ;
44import { CipherData , Encryption } from '../utils/encryption' ;
55import { getKeyVerifier } from '../utils/persistent-unlock' ;
6+ import { parseEnvEntry , serializeEnv } from '../utils/env-utils' ;
7+ import dotenv from 'dotenv' ;
68
79export const inspectCommand : Command = program
810 . createCommand ( 'inspect' )
911 . argument ( '<env_file>' , 'File to inspect' )
10- . action ( async ( envFile ) => {
12+ . option (
13+ '-o, --override [keyvalue...]' ,
14+ 'Override or pass extra environment variable, e.g MY_VAR=abba' ,
15+ parseEnvEntry ,
16+ { } ,
17+ )
18+ . action ( async ( envFile , options ) => {
1119 const fs = getFS ( ) ;
1220 const dirname = path . dirname ( envFile ) ;
1321 const unlockfile = path . join ( dirname , '.dktp.unlocked' ) ;
@@ -17,9 +25,12 @@ export const inspectCommand: Command = program
1725 const [ key , verifier ] = keyVerifier ;
1826 const content = await Encryption . decryptWithKey ( key , verifier , vaultFile ) ;
1927
28+ const env = dotenv . parse ( content ) ;
29+ dotenv . populate ( env , options . override , { override : true } ) ;
30+
2031 if ( updatedValue ) {
2132 await fs . write ( unlockfile , Buffer . from ( updatedValue ) ) ;
2233 }
2334
24- console . log ( content ) ;
35+ console . log ( serializeEnv ( env ) ) ;
2536 } ) ;
0 commit comments