Skip to content

feat: add CLI commands#5

Merged
danpasecinic merged 13 commits intomainfrom
feat/integrate-cli-commands
Jan 25, 2026
Merged

feat: add CLI commands#5
danpasecinic merged 13 commits intomainfrom
feat/integrate-cli-commands

Conversation

@danpasecinic
Copy link
Owner

@danpasecinic danpasecinic commented Jan 25, 2026

Summary

  • Implement all core CLI commands for vault management
  • Add terminal utilities for password input (no-echo) and line reading
  • Split commands into separate files for maintainability

Commands Implemented

Command Description
init Create new vault with master password
add <name> Add password entries to vault
get <name> Retrieve and copy password to clipboard
list List all vault entries
delete <name> Remove entries with confirmation
generate Generate passwords/passphrases with options
totp add/list/<name> TOTP 2FA code management
passkey list/show/delete WebAuthn passkey management

Changes

  • src/cli/terminal.zig - Password input without echo, line reading
  • src/cli/commands/*.zig - Individual command implementations
  • src/core/entry.zig - Added createTotpEntry helper
  • src/main.zig - Command routing to separate modules

Test plan

  • zig build compiles without errors
  • zig build test passes all tests
  • zault init creates vault with password confirmation
  • zault add github.com prompts for credentials and saves
  • zault get github.com copies password to clipboard
  • zault list shows all entries
  • zault generate outputs random password with entropy
  • zault generate --passphrase outputs word-based passphrase
  • zault totp add github.com adds TOTP entry
  • zault totp github.com displays current code
  • zault passkey list shows passkey entries

- Add terminal utility for password input (no-echo)
- Implement vault initialization with password confirmation
- Validate minimum password length (8 chars)
- Create vault at XDG_DATA_HOME/zault/vault.zault
- Open and unlock vault with master password
- Accept entry name as argument or prompt
- Prompt for username (optional), password, and URL (optional)
- Create password entry and save to vault
- Handle errors: vault not found, invalid password, duplicate entry
- Retrieve entry by name from vault
- Copy password to clipboard with configurable timeout
- Display username and URL if available
- Handle TOTP and passkey entry types
- Respect clipboard_enabled config setting
- List all entries in vault with name, type, and username/issuer
- Display entry count
- Handle empty vault case
- Generate random passwords with configurable length
- Generate passphrases with configurable word count
- Show entropy calculation
- Optional clipboard copy with --copy flag
- Respects config defaults for generator options
- Move each command to src/cli/commands/*.zig
- Add delete command implementation
- Keep main.zig as router only
- Add TOTP entries with secret and issuer
- Generate and display current TOTP codes
- List all TOTP entries
- Copy codes to clipboard
- Add createTotpEntry helper in entry.zig
- List all passkey entries with RP ID and user
- Show passkey details (algorithm, counter, etc.)
- Delete passkeys with confirmation
- Mask TOTP secret input (was visible on screen)
- Secure zero generated passwords before deallocation
- Secure zero TOTP code buffer after use
- Consume newline after confirmation prompts
Allow adding TOTP to existing password entries instead of requiring
separate TOTP entries. This enables users to run 'zault totp add github.com'
on an existing password entry to attach 2FA.

Changes:
- Add optional TOTP fields to PasswordEntry (secret, algorithm, digits, period)
- Update serializer with backwards-compatible TOTP field handling
- totp add: Modify existing password entries or create standalone TOTP
- totp get: Check password entries for TOTP configuration
- totp list: Show both standalone TOTP and password+TOTP entries
- Add vault_helpers.zig with openAndUnlock() helper
- Reduces ~40 lines of boilerplate per command using vault
- Add 'zault totp remove <name>' to remove TOTP from entries
- Improve TOTP error messages (invalid base32, etc.)
- Validate base32 secret on add before storing

totp.zig reduced from 482 to 331 lines.
Apply openAndUnlock() helper to all vault-accessing commands:
- add.zig: 125 → 89 lines
- delete.zig: 85 → 51 lines
- get.zig: 95 → 56 lines
- list.zig: 72 → 33 lines
- passkey.zig: 281 → 172 lines

Total reduction: 257 lines (22%) across CLI commands.
@danpasecinic danpasecinic changed the title feat: implement CLI commands (Phase 3) feat: add CLI commands Jan 25, 2026
@danpasecinic danpasecinic self-assigned this Jan 25, 2026
@danpasecinic danpasecinic added the enhancement New feature or request label Jan 25, 2026
@danpasecinic danpasecinic merged commit 4ca6cd1 into main Jan 25, 2026
4 checks passed
@danpasecinic danpasecinic deleted the feat/integrate-cli-commands branch January 25, 2026 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant