Skip to content

Commit 685199d

Browse files
committed
chore: addressed review
[ci skip]
1 parent e65d1b1 commit 685199d

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/secrets/CommandMkdir.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class CommandMkdir extends CommandPolykey {
1313
constructor(...args: ConstructorParameters<typeof CommandPolykey>) {
1414
super(...args);
1515
this.name('mkdir');
16-
this.description('Create a Directory within a Vault');
16+
this.description(
17+
'Create a Directory within a Vault. Empty directories are not a part of the vault and will not be shared when cloning a Vault.',
18+
);
1719
this.argument(
1820
'<secretPath...>',
1921
'Path to where the directory to be created, specified as <vaultName>:<directoryPath>',
@@ -62,28 +64,28 @@ class CommandMkdir extends CommandPolykey {
6264
const writer = response.writable.getWriter();
6365
let first = true;
6466
for (const [vault, path] of secretPaths) {
65-
await writer.write({
66-
nameOrId: vault,
67-
dirName: path,
68-
metadata: first
69-
? { ...auth, options: { recursive: options.recursive } }
70-
: undefined,
71-
});
67+
if (first) {
68+
first = false;
69+
await writer.write({
70+
nameOrId: vault,
71+
dirName: path,
72+
metadata: {
73+
...auth,
74+
options: { recursive: options.recursive },
75+
},
76+
});
77+
} else {
78+
await writer.write({ nameOrId: vault, dirName: path });
79+
}
7280
}
7381
await writer.close();
7482
return response;
7583
}, meta);
7684

77-
// As git does not track empty directories in version control, we need
78-
// to inform the user about this.
79-
process.stderr.write(
80-
'WARNING: Empty directories will not be affected by modifications to the vault state (version change, sharing/cloning, etc.)\n',
81-
);
82-
83-
let shouldError = false;
85+
let hasErrored = false;
8486
for await (const result of response.readable) {
8587
if (result.type === 'error') {
86-
shouldError = true;
88+
hasErrored = true;
8789
let message: string = '';
8890
switch (result.code) {
8991
case 'ENOENT':
@@ -102,7 +104,7 @@ class CommandMkdir extends CommandPolykey {
102104
);
103105
}
104106
}
105-
if (shouldError) {
107+
if (hasErrored) {
106108
throw new ErrorPolykeyCLIMakeDirectory(
107109
'Failed to create one or more directories',
108110
);

0 commit comments

Comments
 (0)