| @@ -8,10 +8,8 @@ import argparse |
| 8 | from yoshi import crypto, database, process |
8 | from yoshi import crypto, database, process |
| 9 | |
9 | |
| 10 | |
10 | |
| 11 | def yoshi(): |
11 | def 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 | |
| |
83 | def _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 | |
| |
90 | def _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: |
107 | def _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 | |
| |
124 | def 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 | |
| 122 | if __name__ == "__main__": |
135 | if __name__ == "__main__": |