()
| 111 | } |
| 112 | |
| 113 | func (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 |
no test coverage detected