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

Function runNote

pkg/cli/cmd/remove/remove.go:120–163  ·  view source on GitHub ↗
(ctx context.DnoteCtx, rowIDArg string)

Source from the content-addressed store, hash-verified

118}
119
120func runNote(ctx context.DnoteCtx, rowIDArg string) error {
121 db := ctx.DB
122
123 noteRowID, err := strconv.Atoi(rowIDArg)
124 if err != nil {
125 return errors.Wrap(err, "invalid rowid")
126 }
127
128 noteInfo, err := database.GetNoteInfo(db, noteRowID)
129 if err != nil {
130 return err
131 }
132
133 output.NoteInfo(os.Stdout, noteInfo)
134
135 ok, err := maybeConfirm("remove this note?", false)
136 if err != nil {
137 return errors.Wrap(err, "getting confirmation")
138 }
139 if !ok {
140 log.Warnf("aborted by user\n")
141 return nil
142 }
143
144 tx, err := db.Begin()
145 if err != nil {
146 return errors.Wrap(err, "beginning a transaction")
147 }
148
149 if _, err = tx.Exec("UPDATE notes SET deleted = ?, dirty = ?, body = ? WHERE uuid = ?", true, true, "", noteInfo.UUID); err != nil {
150 tx.Rollback()
151 return errors.Wrap(err, "removing the note")
152 }
153
154 err = tx.Commit()
155 if err != nil {
156 tx.Rollback()
157 return errors.Wrap(err, "comitting transaction")
158 }
159
160 log.Successf("removed from %s\n", noteInfo.BookLabel)
161
162 return nil
163}
164
165func runBook(ctx context.DnoteCtx, bookLabel string) error {
166 db := ctx.DB

Callers 1

newRunFunction · 0.70

Calls 9

GetNoteInfoFunction · 0.92
NoteInfoFunction · 0.92
WarnfFunction · 0.92
SuccessfFunction · 0.92
maybeConfirmFunction · 0.85
BeginMethod · 0.65
ExecMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected