@@ -24,7 +24,7 @@ class CommandMkdir extends CommandPolykey {
24
24
this . addOption ( binOptions . nodeId ) ;
25
25
this . addOption ( binOptions . clientHost ) ;
26
26
this . addOption ( binOptions . clientPort ) ;
27
- this . addOption ( binOptions . recursive ) ;
27
+ this . addOption ( binOptions . parents ) ;
28
28
this . action ( async ( secretPaths , options ) => {
29
29
secretPaths = secretPaths . map ( ( path : string ) =>
30
30
binParsers . parseSecretPath ( path ) ,
@@ -59,51 +59,53 @@ class CommandMkdir extends CommandPolykey {
59
59
} ,
60
60
logger : this . logger . getChild ( PolykeyClient . name ) ,
61
61
} ) ;
62
- const response = await binUtils . retryAuthentication ( async ( auth ) => {
62
+ const hasErrored = await binUtils . retryAuthentication ( async ( auth ) => {
63
+ // Write directory paths to input stream
63
64
const response =
64
65
await pkClient . rpcClient . methods . vaultsSecretsMkdir ( ) ;
65
66
const writer = response . writable . getWriter ( ) ;
66
67
let first = true ;
67
68
for ( const [ vault , path ] of secretPaths ) {
68
69
await writer . write ( {
69
70
nameOrId : vault ,
70
- dirName : path ,
71
+ dirName : path ?? '/' ,
71
72
metadata : first
72
- ? { ...auth , options : { recursive : options . recursive } }
73
+ ? { ...auth , options : { recursive : options . parents } }
73
74
: undefined ,
74
75
} ) ;
75
76
first = false ;
76
77
}
77
78
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
+ ) ;
101
105
}
102
- process . stderr . write (
103
- `${ error . code } : cannot create directory ${ error . reason } : ${ message } \n` ,
104
- ) ;
105
106
}
106
- }
107
+ return hasErrored ;
108
+ } , meta ) ;
107
109
if ( hasErrored ) {
108
110
throw new ErrorPolykeyCLIMakeDirectory (
109
111
'Failed to create one or more directories' ,
0 commit comments