-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcmd.go
79 lines (74 loc) · 1.83 KB
/
cmd.go
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
package main
import (
"fmt"
"github.com/go-rod/rod-mcp/banner"
"github.com/go-rod/rod-mcp/types"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"os"
)
type SubCfg struct {
Headless bool
ConfigPath string
Mode types.Mode
CDPEndpoint string
}
func RunCmd() (*SubCfg, error) {
subConfig := SubCfg{}
cmd := &cli.App{
Name: "Rod MCP Server",
Description: "Model Context Protocol Server of Rod",
Usage: "rod-mcp is a rod mcp server",
Version: banner.Version,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "use to set Rod MCP Server's config file path, file name is `rod-mcp.yaml`",
Destination: &subConfig.ConfigPath,
}, &cli.StringFlag{
Name: "cdp-endpoint",
Aliases: []string{"cdp"},
Usage: "use to control running browser by cdp",
Destination: &subConfig.CDPEndpoint,
},
&cli.BoolFlag{
Name: "headless",
Aliases: []string{"hl"},
Value: false,
Usage: "use to enable headless,if false browser will shown window",
Destination: &subConfig.Headless,
},
&cli.BoolFlag{
Name: "no-banner",
Aliases: []string{"nb"},
Usage: "use to disable show banner",
},
&cli.BoolFlag{
Name: "vision",
Aliases: []string{"vs"},
Usage: "use to support vision LLM will load vision tools",
},
},
Before: func(c *cli.Context) error {
if !c.Bool("no-banner") {
fmt.Println(banner.ShowBanner())
}
return nil
},
Action: func(c *cli.Context) error {
if c.Bool("headless") {
subConfig.Headless = true
}
if c.Bool("vision") {
subConfig.Mode = types.Vision
}
return nil
},
}
err := cmd.Run(os.Args)
if err != nil {
return nil, errors.Wrapf(err, "run cmd error")
}
return &subConfig, nil
}