MCPcopy Index your code
hub / github.com/dnote/dnote / runBook

Function runBook

pkg/cli/cmd/edit/book.go:72–121  ·  view source on GitHub ↗
(ctx context.DnoteCtx, bookName string)

Source from the content-addressed store, hash-verified

70}
71
72func runBook(ctx context.DnoteCtx, bookName string) error {
73 err := validateRunBookFlags()
74 if err != nil {
75 return errors.Wrap(err, "validating flags.")
76 }
77
78 db := ctx.DB
79 uuid, err := database.GetBookUUID(db, bookName)
80 if err != nil {
81 return errors.Wrap(err, "getting book uuid")
82 }
83
84 name, err := getName(ctx)
85 if err != nil {
86 return errors.Wrap(err, "getting name")
87 }
88
89 err = validate.BookName(name)
90 if err != nil {
91 return errors.Wrap(err, "validating book name")
92 }
93
94 tx, err := ctx.DB.Begin()
95 if err != nil {
96 return errors.Wrap(err, "beginning a transaction")
97 }
98
99 err = database.UpdateBookName(tx, uuid, name)
100 if err != nil {
101 tx.Rollback()
102 return errors.Wrap(err, "updating the book name")
103 }
104
105 bookInfo, err := database.GetBookInfo(tx, uuid)
106 if err != nil {
107 tx.Rollback()
108 return errors.Wrap(err, "getting book info")
109 }
110
111 err = tx.Commit()
112 if err != nil {
113 tx.Rollback()
114 return errors.Wrap(err, "committing a transaction")
115 }
116
117 log.Success("edited the book\n")
118 output.BookInfo(bookInfo)
119
120 return nil
121}

Callers 1

newRunFunction · 0.70

Calls 11

GetBookUUIDFunction · 0.92
BookNameFunction · 0.92
UpdateBookNameFunction · 0.92
GetBookInfoFunction · 0.92
SuccessFunction · 0.92
BookInfoFunction · 0.92
validateRunBookFlagsFunction · 0.85
getNameFunction · 0.85
BeginMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected