(cmd *cobra.Command, args []string)
| 135 | hey journal read 2026-03-15 |
| 136 | hey journal read --html |
| 137 | hey journal read --json`, |
| 138 | RunE: journalReadCommand.run, |
| 139 | Args: cobra.MaximumNArgs(1), |
| 140 | } |
| 141 | |
| 142 | return journalReadCommand |
| 143 | } |
| 144 | |
| 145 | func (c *journalReadCommand) run(cmd *cobra.Command, args []string) error { |
| 146 | if err := requireAuth(); err != nil { |
| 147 | return err |
| 148 | } |
| 149 | |
| 150 | date := time.Now().Format(dateLayout) |
| 151 | if len(args) > 0 { |
| 152 | if _, err := parseDateArg("date", args[0]); err != nil { |
| 153 | return err |
| 154 | } |
| 155 | date = args[0] |
| 156 | } |
| 157 | |
| 158 | ctx := cmd.Context() |
| 159 | content, err := sdk.Journal().GetContent(ctx, date) |
| 160 | if err != nil { |
| 161 | return apierr.FromSDK(err) |
| 162 | } |
| 163 | |
| 164 | // --html writes the entry's HTML and, for a day without one, nothing at all. |
| 165 | if writer.EffectiveFormat() == output.FormatHTML { |
| 166 | if content == "" { |
| 167 | return nil |
| 168 | } |
| 169 | _, err := fmt.Fprintln(cmd.OutOrStdout(), content) |
| 170 | return err |
| 171 | } |
| 172 | |
| 173 | if content == "" { |
| 174 | if writer.IsStyled() { |
| 175 | fmt.Fprintf(cmd.OutOrStdout(), "Journal — %s\n\n(empty)\n", date) |
| 176 | return nil |
| 177 | } |
| 178 | return writeOK(nil, output.WithSummary(fmt.Sprintf("No journal entry for %s", date))) |
| 179 | } |
| 180 | |
| 181 | if writer.IsStyled() { |
| 182 | w := cmd.OutOrStdout() |
| 183 | fmt.Fprintf(w, "Journal — %s\n\n", date) |
| 184 | fmt.Fprintln(w, markdown.Render(htmlutil.ToMarkdown(content), stdoutWidth())) |
nothing calls this directly
no test coverage detected