Skip to content

Commit 0cf528f

Browse files
committed
fix(cli): make interactive vault unlock persistent
1 parent 2c65bae commit 0cf528f

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

‎packages/cli/src/creds.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ Team secrets, the everyday commands:
3939
4040
Personal vault:
4141
logicsrc vault init create it (once)
42-
eval "$(logicsrc vault unlock)" unlock for this shell
42+
logicsrc vault unlock unlock interactively for 15 minutes
43+
eval "$(logicsrc vault unlock --shell)" export a session into this shell
4344
logicsrc vault add login --name GitHub --username me --password -
4445
logicsrc vault list --category social never shows values
4546
logicsrc vault get GitHub --field login.password --reveal

‎packages/opencreds/src/commands.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,14 @@ export function registerCredsCommands(parent: Command, options: RegisterOptions
371371
.command("unlock")
372372
.description("start a session")
373373
.addHelpText("after", examples(`
374-
eval "$($CLI unlock)" unlock for this shell only (nothing written to disk)
375-
$CLI unlock --persist --timeout 30 unlock for scripts for 30 minutes; \`lock\` ends it`))
376-
.option("--persist", "write the session to a 0600 file instead of printing a token")
374+
$CLI unlock unlock interactively for 15 minutes; \`lock\` ends it
375+
eval "$($CLI unlock --shell)" export a session into this shell (nothing written to disk)
376+
$CLI unlock --persist --timeout 30 choose a persisted session lifetime`))
377+
.option("--persist", "write the session to a 0600 file (the default in an interactive terminal)")
378+
.option("--shell", "print an export command for the current shell instead of writing a session file")
377379
.option("--password-stdin", "read the master password from stdin")
378380
.option("--timeout <minutes>", "session lifetime when persisted", (v: string) => Number.parseInt(v, 10), 15)
379-
.action(async function (this: Command, opts: { persist?: boolean; timeout: number; passwordStdin?: boolean }) {
381+
.action(async function (this: Command, opts: { persist?: boolean; shell?: boolean; timeout: number; passwordStdin?: boolean }) {
380382
await run(async () => {
381383
const store = storeFor(this);
382384
const meta = requireMeta(store);
@@ -392,7 +394,11 @@ export function registerCredsCommands(parent: Command, options: RegisterOptions
392394
}
393395
store.appendAudit(auditEvent({ action: "vault.unlock", namespace: meta.namespace, profile: meta.profile }));
394396

395-
if (opts.persist) {
397+
// A plain interactive `unlock` should do what people expect: unlock
398+
// the vault for subsequent commands. The export-only behavior remains
399+
// available behind --shell and for non-interactive/scripted use.
400+
const persist = Boolean(opts.persist) || (!opts.shell && Boolean(process.stdin.isTTY) && !opts.passwordStdin);
401+
if (persist) {
396402
const path = persistSession(userKey, opts.timeout, store.baseDir);
397403
process.stdout.write(`Session written to ${path}, expiring in ${opts.timeout} minutes.\n`);
398404
process.stdout.write(

0 commit comments

Comments
 (0)