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
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.jnss.me/joakim/jadedepo/internal/engine"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
forceDelete bool
|
||||
|
||||
rmCmd = &cobra.Command{
|
||||
Use: "rm [title]",
|
||||
Short: "Remove a note (moves to trash)",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
Run: removeNote,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
rmCmd.Flags().BoolVarP(&forceDelete, "force", "f", false, "Skip confirmation prompt")
|
||||
rootCmd.AddCommand(rmCmd)
|
||||
}
|
||||
|
||||
func removeNote(cmd *cobra.Command, args []string) {
|
||||
jd, err := engine.GetInstance()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Search for note by title
|
||||
searchTitle := strings.Join(args, " ")
|
||||
matches, err := jd.FindNoteByTitle(searchTitle)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error searching for note: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if len(matches) == 0 {
|
||||
fmt.Fprintf(os.Stderr, "No notes found matching '%s'\n", searchTitle)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var noteToDelete *engine.Note
|
||||
|
||||
if len(matches) == 1 {
|
||||
noteToDelete = matches[0]
|
||||
} else {
|
||||
// Multiple matches - show options
|
||||
fmt.Printf("Multiple notes found matching '%s':\n\n", searchTitle)
|
||||
for i, note := range matches {
|
||||
fmt.Printf(" %d. %s (%s)\n", i+1, note.Title, note.Path)
|
||||
}
|
||||
fmt.Print("\nSelect note number (1-", len(matches), "): ")
|
||||
|
||||
var selection int
|
||||
_, err := fmt.Scanf("%d", &selection)
|
||||
if err != nil || selection < 1 || selection > len(matches) {
|
||||
fmt.Fprintf(os.Stderr, "Invalid selection\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
noteToDelete = matches[selection-1]
|
||||
}
|
||||
|
||||
// Confirm deletion
|
||||
if !forceDelete {
|
||||
fmt.Printf("Are you sure you want to delete '%s'? (y/N): ", noteToDelete.Title)
|
||||
var confirm string
|
||||
fmt.Scanln(&confirm)
|
||||
if strings.ToLower(confirm) != "y" && strings.ToLower(confirm) != "yes" {
|
||||
fmt.Println("Deletion cancelled")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Move to trash
|
||||
notePath := filepath.Join(jd.Config.DepoPath, noteToDelete.Path)
|
||||
trashPath := jd.GetTrashPath()
|
||||
|
||||
// Create unique filename in trash (add timestamp to avoid conflicts)
|
||||
timestamp := time.Now().Format("20060102-150405")
|
||||
trashFilename := fmt.Sprintf("%s-%s", timestamp, filepath.Base(noteToDelete.Path))
|
||||
trashDestination := filepath.Join(trashPath, trashFilename)
|
||||
|
||||
if err := os.Rename(notePath, trashDestination); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error moving note to trash: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("Moved '%s' to trash\n", noteToDelete.Title)
|
||||
fmt.Printf("Trash location: %s\n", trashDestination)
|
||||
}
|
||||
Reference in New Issue
Block a user