diff --git a/keepassx/__pycache__/__init__.cpython-311.pyc b/keepassx/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..d88b291 Binary files /dev/null and b/keepassx/__pycache__/__init__.cpython-311.pyc differ diff --git a/keepassx/__pycache__/clipboard.cpython-311.pyc b/keepassx/__pycache__/clipboard.cpython-311.pyc new file mode 100644 index 0000000..ee49c22 Binary files /dev/null and b/keepassx/__pycache__/clipboard.cpython-311.pyc differ diff --git a/keepassx/__pycache__/db.cpython-311.pyc b/keepassx/__pycache__/db.cpython-311.pyc new file mode 100644 index 0000000..bbf5f83 Binary files /dev/null and b/keepassx/__pycache__/db.cpython-311.pyc differ diff --git a/keepassx/__pycache__/main.cpython-311.pyc b/keepassx/__pycache__/main.cpython-311.pyc new file mode 100644 index 0000000..adba688 Binary files /dev/null and b/keepassx/__pycache__/main.cpython-311.pyc differ diff --git a/keepassx/main.py b/keepassx/main.py index cc487e1..7fa58f2 100644 --- a/keepassx/main.py +++ b/keepassx/main.py @@ -79,19 +79,24 @@ def do_list(args): def do_get(args): db = create_db(args) try: - entry = _search_for_entry(db, args.entry_id)[0] + entries = _search_for_entry(db, args.entry_id) + if args.category: + entries = [entry for entry in entries if entry.group.group_name == args.category] + if not entries: + raise EntryNotFoundError("No entries found in the specified category.") + entry = entries[0] except EntryNotFoundError as e: sys.stderr.write(str(e)) sys.stderr.write("\n") return + default_fields = ['title', 'username', 'url', 'notes'] - if args.entry_fields: - fields = args.entry_fields - else: - fields = default_fields + fields = args.entry_fields if args.entry_fields else default_fields + sys.stderr.write('\n') for field in fields: print("%-10s %s" % (field + ':', getattr(entry, field))) + if args.clipboard_copy: clipboard.copy(entry.password) sys.stderr.write("\nPassword has been copied to clipboard.\n") @@ -160,6 +165,7 @@ def create_parser(): get_parser.add_argument('-n', '--no-clipboard-copy', action="store_false", dest="clipboard_copy", default=True, help="Don't copy the password to the clipboard") + get_parser.add_argument('-c', '--category', help='Specify the category of the entry.') get_parser.set_defaults(run=do_get) return parser diff --git a/tests/__pycache__/test_cli.cpython-311.pyc b/tests/__pycache__/test_cli.cpython-311.pyc new file mode 100644 index 0000000..259bd3c Binary files /dev/null and b/tests/__pycache__/test_cli.cpython-311.pyc differ diff --git a/tests/__pycache__/test_clipboard.cpython-311.pyc b/tests/__pycache__/test_clipboard.cpython-311.pyc new file mode 100644 index 0000000..d3d0e94 Binary files /dev/null and b/tests/__pycache__/test_clipboard.cpython-311.pyc differ diff --git a/tests/__pycache__/test_config.cpython-311.pyc b/tests/__pycache__/test_config.cpython-311.pyc new file mode 100644 index 0000000..fa60df5 Binary files /dev/null and b/tests/__pycache__/test_config.cpython-311.pyc differ diff --git a/tests/__pycache__/test_keepassx.cpython-311.pyc b/tests/__pycache__/test_keepassx.cpython-311.pyc new file mode 100644 index 0000000..7fb0b45 Binary files /dev/null and b/tests/__pycache__/test_keepassx.cpython-311.pyc differ diff --git a/tests/test_keepassx.py b/tests/test_keepassx.py index e91d7a8..9363582 100644 --- a/tests/test_keepassx.py +++ b/tests/test_keepassx.py @@ -197,6 +197,38 @@ def test_master_password_unicode(self): # Verify we can read anything from the db. self.assertEqual(len(db.groups), 2) + def test_get_entry_with_category(self): + kdb_contents = open_data_file('password.kdb').read() + db = Database(kdb_contents, self.password) + + # Create a "Backup" group explicitly for testing + backup_group = type('Group', (object,), { + 'group_name': 'Backup', + 'groupid': 999999, + 'level': 0 + }) + db.groups.append(backup_group) + + # Add an entry to the Backup category for testing + db.entries.append( + type('Entry', (object,), { + 'title': 'backup_entry', + 'uuid': 'backup_uuid', + 'group': backup_group, + 'username': 'backup_user', + 'password': 'backup_pass', + 'url': 'backup_url', + 'notes': 'backup_notes', + 'creation_time': datetime.now() + }) + ) + + # Test retrieval with category filtering + entries = [entry for entry in db.entries if entry.group.group_name == 'Backup'] + self.assertEqual(len(entries), 1) + self.assertEqual(entries[0].title, 'backup_entry') + self.assertEqual(entries[0].password, 'backup_pass') + class TestEncodePassword(unittest.TestCase): def test_encode_ascii(self):