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

Function runNote

pkg/cli/cmd/edit/note.go:114–172  ·  view source on GitHub ↗
(ctx context.DnoteCtx, rowIDArg string)

Source from the content-addressed store, hash-verified

112}
113
114func runNote(ctx context.DnoteCtx, rowIDArg string) error {
115 err := validateRunNoteFlags()
116 if err != nil {
117 return errors.Wrap(err, "validating flags.")
118 }
119
120 rowID, err := strconv.Atoi(rowIDArg)
121 if err != nil {
122 return errors.Wrap(err, "invalid rowid")
123 }
124
125 db := ctx.DB
126 note, err := database.GetActiveNote(db, rowID)
127 if err == sql.ErrNoRows {
128 return errors.Errorf("note %d not found", rowID)
129 } else if err != nil {
130 return errors.Wrap(err, "querying the book")
131 }
132
133 content := contentFlag
134
135 // If no flag was provided, launch an editor to get the content
136 if bookFlag == "" && contentFlag == "" {
137 c, err := getContent(ctx, note)
138 if err != nil {
139 return errors.Wrap(err, "getting content from editor")
140 }
141
142 content = c
143 }
144
145 tx, err := ctx.DB.Begin()
146 if err != nil {
147 return errors.Wrap(err, "beginning a transaction")
148 }
149
150 err = updateNote(ctx, tx, note, bookFlag, content)
151 if err != nil {
152 tx.Rollback()
153 return errors.Wrap(err, "updating note fields")
154 }
155
156 noteInfo, err := database.GetNoteInfo(tx, rowID)
157 if err != nil {
158 tx.Rollback()
159 return errors.Wrap(err, "getting note info")
160 }
161
162 err = tx.Commit()
163 if err != nil {
164 tx.Rollback()
165 return errors.Wrap(err, "committing a transaction")
166 }
167
168 log.Success("edited the note\n")
169 output.NoteInfo(os.Stdout, noteInfo)
170
171 return nil

Callers 1

newRunFunction · 0.70

Calls 10

GetActiveNoteFunction · 0.92
GetNoteInfoFunction · 0.92
SuccessFunction · 0.92
NoteInfoFunction · 0.92
validateRunNoteFlagsFunction · 0.85
updateNoteFunction · 0.85
getContentFunction · 0.70
BeginMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected