-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.go
More file actions
57 lines (48 loc) · 1.33 KB
/
Copy pathcli.go
File metadata and controls
57 lines (48 loc) · 1.33 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
package main
import (
"fmt"
"os"
"os/exec"
"github.com/spf13/cobra"
)
func BuildCli() *cobra.Command {
rootCmd := &cobra.Command{
Use: "shard",
Short: "A lightweight and type-safe MCP server for Obsidian that uses Obsidian CLI.",
SilenceErrors: true,
SilenceUsage: true,
}
checkCmd := &cobra.Command{
Use: "check",
Short: "Check if Shard can detect Obsidian CLI",
RunE: func(cmd *cobra.Command, args []string) error {
executable := GetDefaultExecutableName()
localExecutable := "." + string(os.PathSeparator) + executable
if resolved, err := exec.LookPath(localExecutable); err == nil {
executable = resolved
} else if resolved, err := exec.LookPath(executable); err == nil {
executable = resolved
} else {
return fmt.Errorf("obsidian CLI %q not found in current directory or PATH", executable)
}
fmt.Printf("Found the CLI by path '%s'.", executable)
return nil
},
}
startCmd := &cobra.Command{
Use: "start",
Short: "Start an MCP server.",
RunE: func(cmd *cobra.Command, args []string) error {
return StartServer()
},
}
versionCmd := &cobra.Command{
Use: "version",
Short: "Print version of Shard",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(VERSION)
},
}
rootCmd.AddCommand(checkCmd, startCmd, versionCmd)
return rootCmd
}