MCPcopy Create free account
hub / github.com/basecamp/hey-cli / run

Method run

internal/cmd/journal.go:208–277  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

206}
207
208func (c *journalWriteCommand) run(cmd *cobra.Command, args []string) error {
209 if err := requireAuth(); err != nil {
210 return err
211 }
212
213 date := time.Now().Format("2006-01-02")
214 content := c.content
215
216 switch len(args) {
217 case 2:
218 if content != "" {
219 return output.ErrUsage("--content and positional content are mutually exclusive")
220 }
221 if !isDateArg(args[0]) {
222 return output.ErrUsageHint(
223 "first argument must be a date (YYYY-MM-DD) when two positional arguments are given",
224 "hey journal write 2024-01-15 \"Content\" or hey journal write \"Content\"")
225 }
226 date = args[0]
227 content = args[1]
228 case 1:
229 if isDateArg(args[0]) {
230 date = args[0]
231 } else {
232 if content != "" {
233 return output.ErrUsage("--content and positional content are mutually exclusive")
234 }
235 content = args[0]
236 }
237 }
238 ctx := cmd.Context()
239 if content == "" {
240 if !stdinIsTerminal() {
241 var err error
242 content, err = readStdin()
243 if err != nil {
244 return err
245 }
246 if content == "" {
247 return output.ErrUsage("no content provided (use --content to provide inline, or pipe to stdin)")
248 }
249 } else {
250 existing, _ := sdk.Journal().GetContent(ctx, date)
251
252 var err error
253 content, err = editor.Open(existing)
254 if err != nil {
255 return output.ErrAPI(0, fmt.Sprintf("could not open editor: %v", err))
256 }
257 }
258 }
259
260 if err := sdk.Journal().Update(ctx, date, content); err != nil {
261 return convertSDKError(err)
262 }
263
264 if writer.IsStyled() {
265 fmt.Fprintf(cmd.OutOrStdout(), "Journal entry for %s saved.\n", date)

Callers

nothing calls this directly

Calls 11

OpenFunction · 0.92
WithSummaryFunction · 0.92
WithBreadcrumbsFunction · 0.92
requireAuthFunction · 0.85
isDateArgFunction · 0.85
stdinIsTerminalFunction · 0.85
readStdinFunction · 0.85
convertSDKErrorFunction · 0.85
writeOKFunction · 0.85
IsStyledMethod · 0.80
UpdateMethod · 0.65

Tested by

no test coverage detected