Skip to content

Commit 5526a50

Browse files
author
Corentin Mors
committed
Fix password console output and case sensitive on dcli read
Fix #292
1 parent b914433 commit 5526a50

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/command-handlers/passwords.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export const runPassword = async (
2929

3030
if (field === 'otp') {
3131
foundCredentials = foundCredentials.filter((credential) => credential.otpSecret);
32+
33+
if (foundCredentials.length === 0) {
34+
throw new Error('No credential found with OTP.');
35+
}
3236
}
3337

3438
const selectedCredential = await selectCredential(foundCredentials, Boolean(filters?.length));
@@ -60,6 +64,7 @@ export const runPassword = async (
6064

6165
if (output === 'console') {
6266
logger.content(result);
67+
return;
6368
}
6469

6570
const clipboard = new Clipboard();

src/commands/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const rootCommands = (params: { program: Command }) => {
2727

2828
program
2929
.command('read')
30-
.description('Retrieve a secret from the local vault via its path')
30+
.description('Retrieve a secret from the local vault via its path (using <id> is much more efficient)')
3131
.argument('<path>', 'Path to the secret (dl://<title>/<field> or dl://<id>/<field>)')
3232
.action(runRead);
3333

src/modules/database/vaultContent.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ export const getVaultContent = (path: string): string => {
5959
return findVaultContent(vaultContent, parsedPath);
6060
};
6161

62+
const compareStringCaseUnsensitive = (a: string | undefined, b: string | undefined): boolean => {
63+
return a?.toLowerCase() === b?.toLowerCase();
64+
};
65+
6266
export const findVaultContent = (vaultContent: VaultContent, parsedPath: ParsedPath): string => {
6367
const filteredVaultContent: VaultContent = {
6468
credentials: [],
@@ -67,11 +71,15 @@ export const findVaultContent = (vaultContent: VaultContent, parsedPath: ParsedP
6771
};
6872

6973
if (parsedPath.title) {
70-
filteredVaultContent.credentials = vaultContent.credentials.filter(
71-
(credential) => credential.title === parsedPath.title
74+
filteredVaultContent.credentials = vaultContent.credentials.filter((credential) =>
75+
compareStringCaseUnsensitive(credential.title, parsedPath.title)
76+
);
77+
filteredVaultContent.notes = vaultContent.notes.filter((note) =>
78+
compareStringCaseUnsensitive(note.title, parsedPath.title)
79+
);
80+
filteredVaultContent.secrets = vaultContent.secrets.filter((secret) =>
81+
compareStringCaseUnsensitive(secret.title, parsedPath.title)
7282
);
73-
filteredVaultContent.notes = vaultContent.notes.filter((note) => note.title === parsedPath.title);
74-
filteredVaultContent.secrets = vaultContent.secrets.filter((secret) => secret.title === parsedPath.title);
7583
}
7684

7785
if (parsedPath.itemId) {

0 commit comments

Comments
 (0)