Files
joakim 52160345bf Implement Jade CLI v1.0 MVP
Complete implementation of note management CLI with all core features:

Commands:
- add: Create new notes in $EDITOR with auto-generated filenames
- list: Display all notes with titles, paths, and tags
- search: Full-text search via ripgrep, tag-based filtering
- tags: List all tags with occurrence counts
- edit: Fuzzy search and edit notes by title
- rm: Move notes to trash with confirmation prompt

Features:
- Automatic depository structure initialization (.jade/trash/)
- Configurable tag prefix (default '+')
- Parse title from first # heading (filename fallback)
- Extract tags anywhere in content
- Parse both [[wiki-links]] and [markdown](links)
- Trash system with timestamps to prevent conflicts

Technical:
- Global config at ~/.config/jade/config.yml
- Per-depository settings support
- Ripgrep integration for fast search
- $EDITOR integration for note editing
- Comprehensive README with usage examples
2026-01-01 21:54:36 +01:00

72 lines
1.5 KiB
Go

package cmd
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"git.jnss.me/joakim/jadedepo/internal/engine"
"github.com/spf13/cobra"
)
var (
addCmd = &cobra.Command{
Short: "Add note to depository",
Use: "add [title]",
Args: cobra.MinimumNArgs(1),
Run: addNote,
}
)
func init() {
rootCmd.AddCommand(addCmd)
}
func addNote(cmd *cobra.Command, args []string) {
jd, err := engine.GetInstance()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
// Join all args as the title
title := strings.Join(args, " ")
// Convert title to filename
filename := engine.TitleToFilename(title)
notePath := filepath.Join(jd.Config.DepoPath, filename)
// Check if file already exists
if _, err := os.Stat(notePath); err == nil {
fmt.Fprintf(os.Stderr, "Error: note '%s' already exists\n", filename)
os.Exit(1)
}
// Create file with initial heading
initialContent := fmt.Sprintf("# %s\n\n", title)
if err := os.WriteFile(notePath, []byte(initialContent), 0644); err != nil {
fmt.Fprintf(os.Stderr, "Error creating note: %v\n", err)
os.Exit(1)
}
// Open in $EDITOR
editor := os.Getenv("EDITOR")
if editor == "" {
editor = "vi" // fallback
}
editorCmd := exec.Command(editor, notePath)
editorCmd.Stdin = os.Stdin
editorCmd.Stdout = os.Stdout
editorCmd.Stderr = os.Stderr
if err := editorCmd.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error opening editor: %v\n", err)
os.Exit(1)
}
fmt.Printf("Created note: %s\n", filename)
}