-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
executable file
·103 lines (80 loc) · 2.74 KB
/
cli.py
File metadata and controls
executable file
·103 lines (80 loc) · 2.74 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
import argparse
from notebook import Book, Note, NoteCLI, Shelf
def make_parser():
root_parser = argparse.ArgumentParser(
prog="notebook",
description="helps you manage your notebooks in markdown",
epilog="by N. M. Podratz",
)
sub_parsers = root_parser.add_subparsers(
title="Commands",
description="Commands for managing your notebooks",
dest="command",
metavar="COMMAND",
)
bind_book_parser = sub_parsers.add_parser("bind", help="bind your notebook as PDF")
bind_book_parser.set_defaults(func=Note.export)
bind_book_parser.add_argument(
"directory", nargs="?", default="", help="select a subdirectory to bind"
)
create_book_parser = sub_parsers.add_parser("create", help="create a new notebook")
create_book_parser.add_argument(
"location",
nargs="?",
default="~/Notes",
help="Provide a location for your new notebook",
)
list_books_parser = sub_parsers.add_parser(
"list",
help="list your notebooks",
)
list_books_parser.add_argument(
"directory", nargs="?", default="", help="select a subdirectory to display"
)
open_book_parser = sub_parsers.add_parser(
"open", help="open your notebook in your editor"
)
open_book_parser.add_argument(
"directory", nargs="?", default="", help="select a subdirectory to open"
)
show_book_parser = sub_parsers.add_parser(
"show", help="show your notebook in Finder"
)
show_book_parser.add_argument(
"directory", nargs="?", default="", help="select a subdirectory to show"
)
# note group
create_note_parser = sub_parsers.add_parser("note", help="create a new note")
create_note_parser.set_defaults(func=Book.note)
return root_parser
def main():
parser = make_parser()
args = parser.parse_args()
shelf = Shelf.default()
if args.command is None:
book = shelf.selected_book
print(book.details)
elif args.command == "bind":
try:
book = Book(args.directory) or shelf.selected_book
book.export("pdf")
except Exception:
print("Export to pdf failed")
elif args.command == "create":
raise NotImplementedError()
elif args.command == "list":
print(shelf.list())
if args.command == "note":
cli = NoteCLI()
cli.main()
elif args.command == "open":
book = Book(args.directory) or shelf.selected_book
book.open()
elif args.command == "set":
raise NotImplementedError()
elif args.command == "show":
book = Book(args.directory) or shelf.selected_book
book.show()
if __name__ == "__main__":
main()