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:
5 - database: A custom module providing database functionality. 5 - database: A custom module providing database functionality.
6""" 6"""
7 7
8from dataclasses import dataclass
9
8from yoshi import database 10from yoshi import database
9 11
10 12
13@dataclass
11class Account: 14class Account:
12 """Represents a login account.""" 15 """Represents a login account."""
13 16
14 def __init__( 17 uuid: str
15 self, 18 application: str
16 uuid: str, 19 username: str
17 application: str, # pylint: disable=R0913,R0917 20 password: str
18 username: str, # pylint: disable=R0913,R0917 21 url: str
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
27 22
28 def display_account(self) -> None: 23 def display_account(self) -> None:
29 """Print the account details.""" 24 """Print the account details."""
yoshi/cli.py +52 −39
@@ -8,10 +8,8 @@ import argparse
8from yoshi import crypto, database, process 8from yoshi import crypto, database, process
9 9
10 10
11def yoshi(): 11def build_parser() -> argparse.ArgumentParser:
12 """ 12 """Build the CLI's argument parser."""
13 CLI entry point logic, used to parse user inputs.
14 """
15 parser = argparse.ArgumentParser( 13 parser = argparse.ArgumentParser(
16 description="Manage your username and passwords via a convenient CLI vault." 14 description="Manage your username and passwords via a convenient CLI vault."
17 ) 15 )
@@ -79,44 +77,59 @@ def yoshi():
79 type=int, 77 type=int,
80 ) 78 )
81 79
82 args = parser.parse_args() 80 return parser
83 81
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:
84 if args.decrypt: 91 if args.decrypt:
85 if args.keyfile: 92 crypto.decrypt(_key(args, "Please enter your decryption key: "))
86 key = crypto.load_key(args.keyfile[0]) 93 return
87 else: 94 if args.generate:
88 key = input("Please enter your decryption key: ") 95 key = crypto.generate_key()
89 crypto.decrypt(key) 96 print(
90 elif args.encrypt: 97 "WRITE THIS KEY DOWN SOMEWHERE SAFE. YOU WILL NOT BE ABLE TO DECRYPT "
91 if args.generate: 98 "YOUR DATA WITHOUT IT!"
92 key = crypto.generate_key() 99 )
93 print( 100 print(key.decode())
94 "WRITE THIS KEY DOWN SOMEWHERE SAFE. YOU WILL NOT BE ABLE TO DECRYPT " 101 print("\n")
95 "YOUR DATA WITHOUT IT!" 102 else:
96 ) 103 key = _key(args, "Please enter your encryption key: ")
97 print(key.decode()) 104 crypto.encrypt(key)
98 print("\n") 105
99 else: 106
100 if args.keyfile: 107def _vault_command(args) -> None:
101 key = crypto.load_key(args.keyfile[0]) 108 if args.new:
102 else: 109 process.create_account()
103 key = input("Please enter your encryption key: ") 110 elif args.list:
104 crypto.encrypt(key) 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)
105 elif database.check_table(): 131 elif database.check_table():
106 if args.new: 132 _vault_command(args)
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 )
120 133
121 134
122if __name__ == "__main__": 135if __name__ == "__main__":