0ebfaf835d
- 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/
70 lines
1.4 KiB
Go
70 lines
1.4 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
|
|
"git.jnss.me/joakim/jadedepo/internal/engine"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
rootCmd = &cobra.Command{
|
|
Short: "Jade CLI is a note-manager and orchestrator.",
|
|
Run: openDepository,
|
|
}
|
|
)
|
|
|
|
var (
|
|
cfgPath string
|
|
depoPath string
|
|
)
|
|
|
|
func init() {
|
|
cobra.OnInitialize(func() {
|
|
if _, err := engine.Init(cfgPath, depoPath); err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error initializing configuration: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
})
|
|
|
|
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)
|
|
os.Exit(1)
|
|
}
|
|
|
|
os.Exit(0)
|
|
}
|