Skip to content

Commit

Permalink
chore: addressed review
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
aryanjassal committed Oct 14, 2024
1 parent e65d1b1 commit 685199d
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/secrets/CommandMkdir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class CommandMkdir extends CommandPolykey {
constructor(...args: ConstructorParameters<typeof CommandPolykey>) {
super(...args);
this.name('mkdir');
this.description('Create a Directory within a Vault');
this.description(
'Create a Directory within a Vault. Empty directories are not a part of the vault and will not be shared when cloning a Vault.',
);
this.argument(
'<secretPath...>',
'Path to where the directory to be created, specified as <vaultName>:<directoryPath>',
Expand Down Expand Up @@ -62,28 +64,28 @@ class CommandMkdir extends CommandPolykey {
const writer = response.writable.getWriter();
let first = true;
for (const [vault, path] of secretPaths) {
await writer.write({
nameOrId: vault,
dirName: path,
metadata: first
? { ...auth, options: { recursive: options.recursive } }
: undefined,
});
if (first) {
first = false;
await writer.write({
nameOrId: vault,
dirName: path,
metadata: {
...auth,
options: { recursive: options.recursive },
},
});
} else {
await writer.write({ nameOrId: vault, dirName: path });
}
}
await writer.close();
return response;
}, meta);

// As git does not track empty directories in version control, we need
// to inform the user about this.
process.stderr.write(
'WARNING: Empty directories will not be affected by modifications to the vault state (version change, sharing/cloning, etc.)\n',
);

let shouldError = false;
let hasErrored = false;
for await (const result of response.readable) {
if (result.type === 'error') {
shouldError = true;
hasErrored = true;
let message: string = '';
switch (result.code) {
case 'ENOENT':
Expand All @@ -102,7 +104,7 @@ class CommandMkdir extends CommandPolykey {
);
}
}
if (shouldError) {
if (hasErrored) {
throw new ErrorPolykeyCLIMakeDirectory(
'Failed to create one or more directories',
);
Expand Down

0 comments on commit 685199d

Please sign in to comment.