Skip to content

feat: add --password flag for non-interactive CLI usage#275

Merged
MuncleUscles merged 2 commits into
mainfrom
feat/non-interactive-password
Feb 8, 2026
Merged

feat: add --password flag for non-interactive CLI usage#275
MuncleUscles merged 2 commits into
mainfrom
feat/non-interactive-password

Conversation

@MuncleUscles

@MuncleUscles MuncleUscles commented Feb 8, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds --password option to all commands that prompt for password interactively
  • When --password is provided, skips interactive prompts enabling scripted/CI usage
  • Commands updated: account create, account send, account unlock, and all staking write commands (validator-join, validator-deposit, validator-exit, validator-claim, validator-prime, prime-all, set-operator, set-identity, delegator-join, delegator-exit, delegator-claim)

Test plan

  • All 437 existing tests pass
  • Verified account send --password works non-interactively
  • Verified account create --password works non-interactively
  • Verified account unlock --password works non-interactively

Summary by CodeRabbit

  • New Features

    • Added --password option to account commands (create, send, unlock)
    • Added --password option to staking-related commands
  • Dependencies

    • Updated genlayer-js from ^0.18.9 to ^0.18.10

Add --password option to account create, send, unlock, and all staking
write commands (validator-join, validator-deposit, validator-exit,
validator-claim, validator-prime, prime-all, set-operator, set-identity,
delegator-join, delegator-exit, delegator-claim). When provided, skips
interactive password prompts enabling scripted/CI usage.
@coderabbitai

coderabbitai Bot commented Feb 8, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR adds optional password parameters to account and staking CLI commands. When a password is provided via CLI options, it bypasses interactive prompts; otherwise, the existing prompt behavior is preserved. Updates include new password fields across SendOptions, UnlockAccountOptions, CreateAccountOptions, StakingConfig, and related interfaces, plus modifications to BaseAction.createKeypairByName to support programmatic password injection.

Changes

Cohort / File(s) Summary
Dependency Update
package.json
Bumped genlayer-js from ^0.18.9 to ^0.18.10.
Account Commands
src/commands/account/create.ts, src/commands/account/send.ts, src/commands/account/unlock.ts, src/commands/account/index.ts
Added optional password field to CreateAccountOptions, SendOptions, and UnlockAccountOptions interfaces. Updated command handlers to accept --password CLI option and conditionally use provided password vs. prompting user. Modified unlock and send flows to bypass password prompt when password is pre-supplied.
Staking Commands
src/commands/staking/StakingAction.ts, src/commands/staking/index.ts
Added optional password field to StakingConfig and _passwordOverride field to StakingAction class. Extended password handling across credential-related flows to use provided password or fall back to interactive prompt. Added --password option to multiple staking commands (join, deposit, exit, claim, prime, set-operator, set-identity, prime-all, info/delegation variants).
Base Infrastructure
src/lib/actions/BaseAction.ts
Updated createKeypairByName method signature to accept optional passwordInput parameter. Conditional logic now uses supplied password directly or prompts for password confirmation if not provided.
Tests
tests/actions/create.test.ts
Updated test expectation to reflect additional optional third argument (undefined) passed to createKeypairByName.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • cristiam86
  • danielrc888

Poem

🐰 A password now flows through the command,
No prompts to interrupt, a helping hand!
From account to staking, the option spreads,
Interactive or programmed—take both paths instead!
Keystore unlocked with a whisper, not a shout! 🔐

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add --password flag for non-interactive CLI usage' directly and clearly describes the main change: adding a --password flag to enable non-interactive CLI usage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/non-interactive-password

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
tests/actions/create.test.ts (1)

35-46: Consider adding a test case for when --password is provided.

The existing test verifies the undefined case. A test confirming that options.password is forwarded to createKeypairByName (e.g., ("main", false, "mypassword")) would cover the new code path.

src/commands/staking/StakingAction.ts (2)

148-158: No error handling around fromEncryptedJson — wrong --password produces a cryptic ethers error.

When the user supplies --password non-interactively (CI), a wrong password will bubble up an opaque ethers decryption error. Wrapping this in a try/catch with a clear message improves the CI experience. The interactive path in BaseAction.decryptKeystore already handles retries and friendly messages, but this code path bypasses it.

Proposed improvement
     this.startSpinner("Unlocking account...");
 
-    const wallet = await ethers.Wallet.fromEncryptedJson(keystoreJson, password);
-    return wallet.privateKey;
+    try {
+      const wallet = await ethers.Wallet.fromEncryptedJson(keystoreJson, password);
+      return wallet.privateKey;
+    } catch {
+      throw new Error(`Failed to unlock account '${accountName}'. Please check your password.`);
+    }
   }

184-218: Duplicated password-override wiring in getViemClients and getStakingClient.

Lines 58-60 and 192-194 are identical. Consider extracting to a small helper like applyConfigOverrides(config) to keep the two methods in sync as more overrides are added. Low priority.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@MuncleUscles MuncleUscles merged commit c5fffa6 into main Feb 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant