MCPcopy Index your code
hub / github.com/cloudspannerecosystem/spanner-cli / RunInteractive

Method RunInteractive

cli.go:113–230  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

111}
112
113func (c *Cli) RunInteractive() int {
114 rl, err := readline.NewEx(&readline.Config{
115 Stdin: c.InStream,
116 HistoryFile: c.HistoryFile,
117 })
118 if err != nil {
119 return c.ExitOnError(err)
120 }
121
122 exists, err := c.Session.DatabaseExists()
123 if err != nil {
124 return c.ExitOnError(err)
125 }
126 if exists {
127 fmt.Fprintf(c.OutStream, "Connected.\n")
128 } else {
129 return c.ExitOnError(fmt.Errorf("unknown database %q", c.Session.databaseId))
130 }
131
132 for {
133 prompt := c.getInterpolatedPrompt()
134 rl.SetPrompt(prompt)
135
136 input, err := readInteractiveInput(rl, prompt)
137 if err == io.EOF {
138 return c.Exit()
139 }
140 if err == readline.ErrInterrupt {
141 return c.Exit()
142 }
143 if err != nil {
144 c.PrintInteractiveError(err)
145 continue
146 }
147
148 stmt, err := BuildStatementWithComments(input.statementWithoutComments, input.statement)
149 if err != nil {
150 c.PrintInteractiveError(err)
151 continue
152 }
153
154 if _, ok := stmt.(*ExitStatement); ok {
155 return c.Exit()
156 }
157
158 if s, ok := stmt.(*UseStatement); ok {
159 newSession, err := createSession(c.Session.projectId, c.Session.instanceId, s.Database, c.Credential, c.Priority,
160 s.Role, c.Endpoint, c.Session.directedRead, c.SkipTLSVerify, c.Session.protoDescriptor)
161 if err != nil {
162 c.PrintInteractiveError(err)
163 continue
164 }
165
166 exists, err := newSession.DatabaseExists()
167 if err != nil {
168 newSession.Close()
169 c.PrintInteractiveError(err)
170 continue

Callers 1

mainFunction · 0.95

Calls 15

ExitOnErrorMethod · 0.95
getInterpolatedPromptMethod · 0.95
ExitMethod · 0.95
PrintInteractiveErrorMethod · 0.95
PrintProgressingMarkMethod · 0.95
PrintResultMethod · 0.95
readInteractiveInputFunction · 0.85
createSessionFunction · 0.85
confirmFunction · 0.85
handleInterruptFunction · 0.85
DatabaseExistsMethod · 0.80

Tested by

no test coverage detected