@@ -24,7 +24,7 @@ class CommandMkdir extends CommandPolykey {
2424 this . addOption ( binOptions . nodeId ) ;
2525 this . addOption ( binOptions . clientHost ) ;
2626 this . addOption ( binOptions . clientPort ) ;
27- this . addOption ( binOptions . recursive ) ;
27+ this . addOption ( binOptions . parents ) ;
2828 this . action ( async ( secretPaths , options ) => {
2929 secretPaths = secretPaths . map ( ( path : string ) =>
3030 binParsers . parseSecretPath ( path ) ,
@@ -59,51 +59,53 @@ class CommandMkdir extends CommandPolykey {
5959 } ,
6060 logger : this . logger . getChild ( PolykeyClient . name ) ,
6161 } ) ;
62- const response = await binUtils . retryAuthentication ( async ( auth ) => {
62+ const hasErrored = await binUtils . retryAuthentication ( async ( auth ) => {
63+ // Write directory paths to input stream
6364 const response =
6465 await pkClient . rpcClient . methods . vaultsSecretsMkdir ( ) ;
6566 const writer = response . writable . getWriter ( ) ;
6667 let first = true ;
6768 for ( const [ vault , path ] of secretPaths ) {
6869 await writer . write ( {
6970 nameOrId : vault ,
70- dirName : path ,
71+ dirName : path ?? '/' ,
7172 metadata : first
72- ? { ...auth , options : { recursive : options . recursive } }
73+ ? { ...auth , options : { recursive : options . parents } }
7374 : undefined ,
7475 } ) ;
7576 first = false ;
7677 }
7778 await writer . close ( ) ;
78- return response ;
79- } , meta ) ;
80-
81- let hasErrored = false ;
82- for await ( const result of response . readable ) {
83- if ( result . type === 'error' ) {
84- // TS cannot properly evaluate a type this deeply nested, so we use
85- // the as keyword to help it. Inside this block, the type of data is
86- // ensured to be 'error'.
87- const error = result as ErrorMessage ;
88- hasErrored = true ;
89- let message : string = '' ;
90- switch ( error . code ) {
91- case 'ENOENT' :
92- message = 'No such secret or directory' ;
93- break ;
94- case 'EEXIST' :
95- message = 'Secret or directory exists' ;
96- break ;
97- default :
98- throw new ErrorPolykeyCLIUncaughtException (
99- `Unexpected error code: ${ error . code } ` ,
100- ) ;
79+ // Print out incoming data to standard out, or incoming errors to
80+ // standard error.
81+ let hasErrored = false ;
82+ for await ( const result of response . readable ) {
83+ if ( result . type === 'error' ) {
84+ // TS cannot properly evaluate a type this deeply nested, so we use
85+ // the as keyword to help it. Inside this block, the type of data
86+ // is ensured to be 'error'.
87+ const error = result as ErrorMessage ;
88+ hasErrored = true ;
89+ let message : string = '' ;
90+ switch ( error . code ) {
91+ case 'ENOENT' :
92+ message = 'No such secret or directory' ;
93+ break ;
94+ case 'EEXIST' :
95+ message = 'Secret or directory exists' ;
96+ break ;
97+ default :
98+ throw new ErrorPolykeyCLIUncaughtException (
99+ `Unexpected error code: ${ error . code } ` ,
100+ ) ;
101+ }
102+ process . stderr . write (
103+ `${ error . code } : cannot create directory ${ error . reason } : ${ message } \n` ,
104+ ) ;
101105 }
102- process . stderr . write (
103- `${ error . code } : cannot create directory ${ error . reason } : ${ message } \n` ,
104- ) ;
105106 }
106- }
107+ return hasErrored ;
108+ } , meta ) ;
107109 if ( hasErrored ) {
108110 throw new ErrorPolykeyCLIMakeDirectory (
109111 'Failed to create one or more directories' ,
0 commit comments