cmd

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CaptureCmd = &cobra.Command{
	Use:   "capture [text]",
	Short: "Quick capture to daily note",
	Long: `Quickly capture text to today's daily note.
	
Examples:
  jotr capture "Meeting with team"
  jotr capture --task "Review PR #123"
  jotr cap "Quick thought"`,
	Aliases: []string{"cap"},
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return fmt.Errorf("text to capture is required")
		}

		cfg, err := config.LoadWithContext(cmd.Context(), "")
		if err != nil {
			return err
		}

		text := strings.Join(args, " ")
		return captureText(cmd.Context(), cfg, text)
	},
}
View Source
var DailyCmd = &cobra.Command{
	Use:     "daily",
	Short:   "Create or open daily note",
	Long:    `Create or open today's daily note.`,
	Aliases: []string{"d"},
	RunE: func(cmd *cobra.Command, args []string) error {
		cfg, err := config.LoadWithContext(cmd.Context(), "")
		if err != nil {
			return err
		}

		dateOption.SetTargetDate()
		opt := ensureDailyContentDate(&dateOption)

		if len(args) > 0 {
			switch args[0] {
			case "append":
				return appendDailyNote(cmd.Context(), cfg, args[1:], opt)
			case "prepend":
				return prependDailyNote(cmd.Context(), cfg, args[1:], opt)
			case "read":
				return readDailyNote(cmd.Context(), cfg, opt)
			default:
				return fmt.Errorf("unknown daily action: %s (use append, prepend, or read)", args[0])
			}
		}

		notePath := notes.BuildDailyNotePath(cfg.DiaryPath, dateOption.Date)

		if outputOption.PathOnly {
			fmt.Println(notePath)
			return nil
		}

		if _, err := os.Stat(notePath); os.IsNotExist(err) {
			sections := notes.BuildDailyNoteSections(cfg)
			if err := notes.CreateDailyNote(cmd.Context(), notePath, sections, dateOption.Date); err != nil {
				return fmt.Errorf("failed to create daily note: %w", err)
			}
			fmt.Printf("✓ Created: %s\n", notePath)
		}

		return openInEditor(cmd.Context(), notePath)
	},
}
View Source
var NoteCmd = &cobra.Command{
	Use:     "note",
	Short:   "Create, open, or manage notes",
	Aliases: []string{"n"},
	RunE: func(cmd *cobra.Command, args []string) error {
		return cmd.Help()
	},
}
View Source
var ReadCmd = &cobra.Command{
	Use:   "read",
	Short: "Read note contents",
	Long: `Display the contents of a note in the terminal.

You can read notes by name (fuzzy match) or by exact path.

Examples:
  jotr read --file "My Note"
  jotr read --path "diary/2024-01-15.md"
  jotr read --file "Project" --lines 50
  jotr read --path "notes/ideas.md" --format raw`,
	RunE: func(cmd *cobra.Command, args []string) error {
		fileFlag, _ := cmd.Flags().GetString("file")
		pathFlag, _ := cmd.Flags().GetString("path")
		linesFlag, _ := cmd.Flags().GetInt("lines")
		formatFlag, _ := cmd.Flags().GetString("format")

		ctx := cmd.Context()
		cfg, err := config.LoadWithContext(ctx, "")
		if err != nil {
			return fmt.Errorf("failed to load config: %w", err)
		}

		var notePath string

		if fileFlag != "" {
			notePath, err = findNoteByName(ctx, cfg, fileFlag)
			if err != nil {
				return err
			}
		} else if pathFlag != "" {
			notePath = filepath.Join(cfg.Paths.BaseDir, pathFlag)
			if !utils.FileExists(notePath) {
				return fmt.Errorf("note not found: %s", pathFlag)
			}
		} else {
			return fmt.Errorf("either --file or --path must be specified")
		}

		content, err := os.ReadFile(notePath)
		if err != nil {
			return fmt.Errorf("failed to read note: %w", err)
		}

		contentStr := string(content)
		if linesFlag > 0 {
			lines := strings.Split(contentStr, "\n")
			if len(lines) > linesFlag {
				totalLines := len(lines)
				lines = lines[:linesFlag]
				contentStr = strings.Join(lines, "\n")
				contentStr += fmt.Sprintf("\n\n%s (%d more lines)", lipgloss.NewStyle().Foreground(output.SecondaryColor).Render("..."), totalLines-linesFlag)
			}
		}

		switch formatFlag {
		case "raw":
			fmt.Print(contentStr)
		case "pretty":
			fmt.Println(formatPretty(contentStr, filepath.Base(notePath)))
		default:
			fmt.Println(formatPretty(contentStr, filepath.Base(notePath)))
		}

		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL