MCPcopy
hub / github.com/dnote/dnote / newRun

Function newRun

pkg/cli/cmd/add/add.go:105–142  ·  view source on GitHub ↗
(ctx context.DnoteCtx)

Source from the content-addressed store, hash-verified

103}
104
105func newRun(ctx context.DnoteCtx) infra.RunEFunc {
106 return func(cmd *cobra.Command, args []string) error {
107 bookName := args[0]
108 if err := validate.BookName(bookName); err != nil {
109 return errors.Wrap(err, "invalid book name")
110 }
111
112 content, err := getContent(ctx)
113 if err != nil {
114 return errors.Wrap(err, "getting content")
115 }
116 if content == "" {
117 return errors.New("Empty content")
118 }
119
120 ts := time.Now().UnixNano()
121 noteRowID, err := writeNote(ctx, bookName, content, ts)
122 if err != nil {
123 return errors.Wrap(err, "Failed to write note")
124 }
125
126 log.Successf("added to %s\n", bookName)
127
128 db := ctx.DB
129 info, err := database.GetNoteInfo(db, noteRowID)
130 if err != nil {
131 return err
132 }
133
134 output.NoteInfo(os.Stdout, info)
135
136 if err := upgrade.Check(ctx); err != nil {
137 log.Error(errors.Wrap(err, "automatically checking updates").Error())
138 }
139
140 return nil
141 }
142}
143
144func writeNote(ctx context.DnoteCtx, bookLabel string, content string, ts int64) (int, error) {
145 tx, err := ctx.DB.Begin()

Callers 1

NewCmdFunction · 0.70

Calls 11

BookNameFunction · 0.92
SuccessfFunction · 0.92
GetNoteInfoFunction · 0.92
NoteInfoFunction · 0.92
CheckFunction · 0.92
ErrorFunction · 0.92
writeNoteFunction · 0.85
NewMethod · 0.80
getContentFunction · 0.70
NowMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected