krz/yoshi-cli

Archived

A password manager for the command line. cli password-manager terminal

Commit d3347b2363

d3347b2363fa8e79a1540870ed6db2cfa9030a70

parent: e724aec083

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-22 20:15 UTC

Add Qlty config; split the CLI and make Account a dataclass

build_parser, _crypto_command, and _vault_command replace one long
function; _key reads --keyfile or prompts. CLI output is unchanged.

Layout: unified · split

.qlty/.gitignore added +7
@@ -0,0 +1,7 @@
1*
2!configs
3!configs/**
4!hooks
5!hooks/**
6!qlty.toml
7!.gitignore
.qlty/qlty.toml added +44
@@ -0,0 +1,44 @@
1config_version = "0"
2
3exclude_patterns = [
4 "**/vendor/**",
5 "**/node_modules/**",
6 "**/testdata/**",
7 "**/dist/**",
8 "**/.build/**",
9 "**/build/**",
10 "**/*.min.*",
11 "**/generated/**",
12 ".claude/**",
13 "**/Pods/**",
14]
15
16test_patterns = [
17 "**/test/**",
18 "**/tests/**",
19 "**/Tests/**",
20 "**/*_test.*",
21 "**/test_*.*",
22 "**/*.test.*",
23 "**/*Tests.swift",
24 "e2e/**",
25]
26
27[[source]]
28name = "default"
29default = true
30
31[[plugin]]
32name = "osv-scanner"
33
34[[plugin]]
35name = "trufflehog"
36
37# Early returns are guard clauses, which keep the happy path unindented.
38[smells.return_statements]
39enabled = false
40
41# Total file complexity is the sum of its functions, which function_complexity
42# already checks.
43[smells.file_complexity]
44enabled = false
yoshi/account.py +8 −13
@@ -5,25 +5,20 @@ Modules imported:
55 - database: A custom module providing database functionality.
66"""
77
8from dataclasses import dataclass
9
810from yoshi import database
911
1012
13@dataclass
1114class Account:
1215 """Represents a login account."""
1316
14 def __init__(
15 self,
16 uuid: str,
17 application: str, # pylint: disable=R0913,R0917
18 username: str, # pylint: disable=R0913,R0917
19 password: str,
20 url: str,
21 ) -> None: # pylint: disable=R0913,R0917
22 self.uuid = uuid
23 self.application = application
24 self.username = username
25 self.password = password
26 self.url = url
17 uuid: str
18 application: str
19 username: str
20 password: str
21 url: str
2722
2823 def display_account(self) -> None:
2924 """Print the account details."""
yoshi/cli.py +52 −39
@@ -8,10 +8,8 @@ import argparse
88from yoshi import crypto, database, process
99
1010
11def yoshi():
12 """
13 CLI entry point logic, used to parse user inputs.
14 """
11def build_parser() -> argparse.ArgumentParser:
12 """Build the CLI's argument parser."""
1513 parser = argparse.ArgumentParser(
1614 description="Manage your username and passwords via a convenient CLI vault."
1715 )
@@ -79,44 +77,59 @@ def yoshi():
7977 type=int,
8078 )
8179
82 args = parser.parse_args()
80 return parser
8381
82
83def _key(args, prompt: str):
84 """The key from --keyfile, or typed in at *prompt*."""
85 if args.keyfile:
86 return crypto.load_key(args.keyfile[0])
87 return input(prompt)
88
89
90def _crypto_command(args) -> None:
8491 if args.decrypt:
85 if args.keyfile:
86 key = crypto.load_key(args.keyfile[0])
87 else:
88 key = input("Please enter your decryption key: ")
89 crypto.decrypt(key)
90 elif args.encrypt:
91 if args.generate:
92 key = crypto.generate_key()
93 print(
94 "WRITE THIS KEY DOWN SOMEWHERE SAFE. YOU WILL NOT BE ABLE TO DECRYPT "
95 "YOUR DATA WITHOUT IT!"
96 )
97 print(key.decode())
98 print("\n")
99 else:
100 if args.keyfile:
101 key = crypto.load_key(args.keyfile[0])
102 else:
103 key = input("Please enter your encryption key: ")
104 crypto.encrypt(key)
92 crypto.decrypt(_key(args, "Please enter your decryption key: "))
93 return
94 if args.generate:
95 key = crypto.generate_key()
96 print(
97 "WRITE THIS KEY DOWN SOMEWHERE SAFE. YOU WILL NOT BE ABLE TO DECRYPT "
98 "YOUR DATA WITHOUT IT!"
99 )
100 print(key.decode())
101 print("\n")
102 else:
103 key = _key(args, "Please enter your encryption key: ")
104 crypto.encrypt(key)
105
106
107def _vault_command(args) -> None:
108 if args.new:
109 process.create_account()
110 elif args.list:
111 process.list_accounts()
112 elif args.edit:
113 process.edit_account(args.uuid[0], args.field[0])
114 elif args.delete:
115 process.delete_account(args.uuid[0])
116 elif args.purge:
117 process.purge_accounts()
118 else:
119 raise TypeError(
120 "Please specify a command or use the --help flag for more information."
121 )
122
123
124def yoshi():
125 """
126 CLI entry point logic, used to parse user inputs.
127 """
128 args = build_parser().parse_args()
129 if args.decrypt or args.encrypt:
130 _crypto_command(args)
105131 elif database.check_table():
106 if args.new:
107 process.create_account()
108 elif args.list:
109 process.list_accounts()
110 elif args.edit:
111 process.edit_account(args.uuid[0], args.field[0])
112 elif args.delete:
113 process.delete_account(args.uuid[0])
114 elif args.purge:
115 process.purge_accounts()
116 else:
117 raise TypeError(
118 "Please specify a command or use the --help flag for more information."
119 )
132 _vault_command(args)
120133
121134
122135if __name__ == "__main__":