Add root command to open depository with $EDITOR

- Implement openDepository function in cmd/root.go to open the depository directory in $EDITOR
- Falls back to vi if $EDITOR is not set
- Update README.md with new usage section documenting bare 'jade' command
- Include config.go changes that move config location to depository/.jade/
This commit is contained in:
2026-01-02 20:18:50 +01:00
parent 52160345bf
commit 0ebfaf835d
3 changed files with 69 additions and 34 deletions
+28 -1
View File
@@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"os"
"os/exec"
"git.jnss.me/joakim/jadedepo/internal/engine"
"github.com/spf13/cobra"
@@ -11,6 +12,7 @@ import (
var (
rootCmd = &cobra.Command{
Short: "Jade CLI is a note-manager and orchestrator.",
Run: openDepository,
}
)
@@ -27,11 +29,36 @@ func init() {
}
})
rootCmd.PersistentFlags().StringVar(&cfgPath, "config", "", "Configuration path. Default $HOME/.config/jade")
rootCmd.PersistentFlags().StringVar(&cfgPath, "config", "", "Configuration file path. Default <depo>/.jade/config.yml")
rootCmd.PersistentFlags().StringVar(&depoPath, "depo", "", "Depository path. Default $HOME/jade-depository")
}
func openDepository(cmd *cobra.Command, args []string) {
jd, err := engine.GetInstance()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
// Get editor from environment variable, fallback to vi
editor := os.Getenv("EDITOR")
if editor == "" {
editor = "vi"
}
// Open the depository directory with the editor
editorCmd := exec.Command(editor, jd.Config.DepoPath)
editorCmd.Stdin = os.Stdin
editorCmd.Stdout = os.Stdout
editorCmd.Stderr = os.Stderr
if err := editorCmd.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error opening depository: %v\n", err)
os.Exit(1)
}
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)