-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbookstack
More file actions
executable file
·80 lines (63 loc) · 2.06 KB
/
Copy pathbookstack
File metadata and controls
executable file
·80 lines (63 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
from pathlib import Path
import argparse
from bookshelfmanager import BookshelfManager
import sys
def get_default_data_path() -> Path:
"""Get default data file path in user's home directory."""
return Path.home() / '.local' / 'share' / 'bookshelf' / 'books.json'
def parse_arguments() -> argparse.Namespace:
"""Parse command line arguments."""
parser = argparse.ArgumentParser(
description="Visualize your personal bookshelf in ASCII art!",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
%(prog)s --display # Show bookshelf
%(prog)s --add # Add a new book
%(prog)s --display --out shelf.txt # Save to file
%(prog)s --data ~/my-books.json --add # Use custom data file
"""
)
parser.add_argument(
'--display', action='store_true',
help='Display the bookshelf'
)
parser.add_argument(
'--add', action='store_true',
help='Add a new book interactively'
)
parser.add_argument(
'--out', metavar='FILE',
help='Save output to file instead of displaying'
)
parser.add_argument(
'--data', metavar='FILE', type=Path,
default=get_default_data_path(),
help='Data file path (default: %(default)s)'
)
parser.add_argument(
'--reset', action='store_true',
help='Reset to default bookshelf'
)
args = parser.parse_args()
if not any([args.display, args.add, args.reset]):
parser.print_help()
sys.exit(0)
return args
def main():
"""Main application entry point."""
args = parse_arguments()
manager = BookshelfManager(args.data)
manager.load_books()
if args.reset:
if manager.reset_to_default():
print("Bookshelf reset to default books")
else:
print("Failed to reset bookshelf")
elif args.add:
manager.add_book_interactive()
elif args.display:
manager.display_bookshelf(args.out)
if __name__ == "__main__":
main()