Skip to content

Commit c53886e

Browse files
committed
chore: updated behaviour of mkdir command
[ci skip]
1 parent 219b965 commit c53886e

1 file changed

Lines changed: 25 additions & 13 deletions

File tree

src/secrets/CommandMkdir.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ class CommandMkdir extends CommandPolykey {
1111
this.name('mkdir');
1212
this.description('Create a Directory within a Vault');
1313
this.argument(
14-
'<secretPath>',
14+
'<secretPath...>',
1515
'Path to where the directory to be created, specified as <vaultName>:<directoryPath>',
16-
binParsers.parseSecretPathValue,
1716
);
1817
this.option('-r, --recursive', 'Create the directory recursively');
1918
this.addOption(binOptions.nodeId);
2019
this.addOption(binOptions.clientHost);
2120
this.addOption(binOptions.clientPort);
22-
this.action(async (secretPath, options) => {
21+
this.addOption(binOptions.recursive);
22+
this.action(async (secretPaths, options) => {
23+
secretPaths = secretPaths.map((path: string) =>
24+
binParsers.parseSecretPathValue(path),
25+
);
2326
const { default: PolykeyClient } = await import(
2427
'polykey/dist/PolykeyClient'
2528
);
@@ -50,16 +53,25 @@ class CommandMkdir extends CommandPolykey {
5053
},
5154
logger: this.logger.getChild(PolykeyClient.name),
5255
});
53-
await binUtils.retryAuthentication(
54-
(auth) =>
55-
pkClient.rpcClient.methods.vaultsSecretsMkdir({
56-
metadata: auth,
57-
nameOrId: secretPath[0],
58-
dirName: secretPath[1],
59-
recursive: options.recursive,
60-
}),
61-
meta,
62-
);
56+
await binUtils.retryAuthentication(async (auth) => {
57+
const response =
58+
await pkClient.rpcClient.methods.vaultsSecretsMkdir();
59+
const writer = response.writable.getWriter();
60+
let first = true;
61+
for (const [vault, path] of secretPaths) {
62+
await writer.write({
63+
nameOrId: vault,
64+
dirName: path,
65+
metadata: first
66+
? { ...auth, options: { recursive: options.recursive } }
67+
: undefined,
68+
});
69+
}
70+
await writer.close();
71+
for await (const result of response.readable) {
72+
if (result.error != null) console.error(result.error);
73+
}
74+
}, meta);
6375
} finally {
6476
if (pkClient! != null) await pkClient.stop();
6577
}

0 commit comments

Comments
 (0)