MCPcopy
hub / github.com/cayleygraph/cayley / Repl

Function Repl

internal/repl/repl.go:90–224  ·  view source on GitHub ↗
(ctx context.Context, h *graph.Handle, queryLanguage string, timeout time.Duration)

Source from the content-addressed store, hash-verified

88)
89
90func Repl(ctx context.Context, h *graph.Handle, queryLanguage string, timeout time.Duration) error {
91 if queryLanguage == "" {
92 queryLanguage = defaultLanguage
93 }
94 l := query.GetLanguage(queryLanguage)
95 if l == nil || l.REPL == nil {
96 return fmt.Errorf("unsupported query language: %q", queryLanguage)
97 }
98 ses := l.REPL(h.QuadStore)
99
100 term, err := terminal(history)
101 if os.IsNotExist(err) {
102 fmt.Printf("creating new history file: %q\n", history)
103 }
104 defer persist(term, history)
105
106 var (
107 prompt = ps1
108
109 code string
110 )
111
112 newCtx := func() (context.Context, func()) { return ctx, func() {} }
113 if timeout > 0 {
114 newCtx = func() (context.Context, func()) { return context.WithTimeout(ctx, timeout) }
115 }
116
117 for {
118 select {
119 case <-ctx.Done():
120 return ctx.Err()
121 default:
122 }
123 if len(code) == 0 {
124 prompt = ps1
125 } else {
126 prompt = ps2
127 }
128 line, err := term.Prompt(prompt)
129 if err != nil {
130 if err == io.EOF {
131 fmt.Println()
132 return nil
133 }
134 return err
135 }
136
137 term.AppendHistory(line)
138
139 line = strings.TrimSpace(line)
140 if len(line) == 0 || line[0] == '#' {
141 continue
142 }
143
144 if code == "" {
145 cmd, args := splitLine(line)
146
147 switch cmd {

Callers 1

NewReplCmdFunction · 0.92

Calls 12

GetLanguageFunction · 0.92
SetVFunction · 0.92
terminalFunction · 0.85
persistFunction · 0.85
splitLineFunction · 0.85
RunFunction · 0.85
ParseMethod · 0.80
ErrorfMethod · 0.65
ErrMethod · 0.65
AddQuadMethod · 0.65
RemoveQuadMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected