-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_config_check.go
More file actions
91 lines (75 loc) · 2.47 KB
/
cmd_config_check.go
File metadata and controls
91 lines (75 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/voilelab/gonovelmaker/internal/obsidian"
)
type ConfigCheckCmd struct {
cmd *cobra.Command
}
func NewConfigCheckCmd() *ConfigCheckCmd {
c := &ConfigCheckCmd{}
c.cmd = &cobra.Command{
Use: "config-check",
Short: "Check if chapter, character, and rewrite prompt templates can be parsed successfully",
Long: `Check if chapter, character, and rewrite prompt templates can be parsed successfully.
This command reads Config/chapter_prompt.md, Config/character_prompt.md, and
Config/rewrite_prompt.md from the vault and attempts to parse them. It reports
any errors in the frontmatter or template syntax.
Example:
novelmaker-obs config-check
novelmaker-obs config-check --vault /path/to/vault`,
RunE: c.run,
}
c.cmd.Flags().StringP("vault", "v", ".", "Path to the Obsidian vault")
return c
}
func (c *ConfigCheckCmd) run(cmd *cobra.Command, args []string) error {
vaultPath, _ := cmd.Flags().GetString("vault")
// Open the vault
vault, err := obsidian.NewVault(vaultPath)
if err != nil {
return fmt.Errorf("failed to open vault: %w", err)
}
fmt.Println("Checking prompt templates...")
fmt.Println()
// Test chapter prompt
fmt.Println("📄 Checking Config/chapter_prompt.md...")
chapterPrompt, err := vault.LoadChapterPrompt()
if err != nil {
fmt.Fprintf(os.Stderr, "❌ Failed to parse chapter prompt: %v\n", err)
return err
}
fmt.Println("✅ Chapter prompt parsed successfully")
if chapterPrompt.System != "" {
fmt.Printf(" System prompt: %.80s...\n", chapterPrompt.System)
}
fmt.Println()
// Test character prompt
fmt.Println("📄 Checking Config/character_prompt.md...")
characterPrompt, err := vault.LoadCharacterPrompt()
if err != nil {
fmt.Fprintf(os.Stderr, "❌ Failed to parse character prompt: %v\n", err)
return err
}
fmt.Println("✅ Character prompt parsed successfully")
if characterPrompt.System != "" {
fmt.Printf(" System prompt: %.80s...\n", characterPrompt.System)
}
fmt.Println()
// Test rewrite prompt
fmt.Println("📄 Checking Config/rewrite_prompt.md...")
rewritePrompt, err := vault.LoadRewritePrompt()
if err != nil {
fmt.Fprintf(os.Stderr, "❌ Failed to parse rewrite prompt: %v\n", err)
return err
}
fmt.Println("✅ Rewrite prompt parsed successfully")
if rewritePrompt.System != "" {
fmt.Printf(" System prompt: %.80s...\n", rewritePrompt.System)
}
fmt.Println()
fmt.Println("🎉 All prompt templates are valid!")
return nil
}