runConsole runs a console for sql operation in command line.
(cmd *Command, args []string)
| 318 | |
| 319 | // runConsole runs a console for sql operation in command line. |
| 320 | func runConsole(cmd *Command, args []string) { |
| 321 | configFile = utils.HomeDirExpand(configFile) |
| 322 | |
| 323 | commonFlagsInit(cmd) |
| 324 | |
| 325 | var err error |
| 326 | // load config |
| 327 | if conf.GConf, err = conf.LoadConfig(configFile); err != nil { |
| 328 | ConsoleLog.WithError(err).Error("load config file failed") |
| 329 | SetExitStatus(1) |
| 330 | ExitIfErrors() |
| 331 | } |
| 332 | |
| 333 | if len(args) == 1 { |
| 334 | dsn = args[0] |
| 335 | } |
| 336 | |
| 337 | if dsn == "" { |
| 338 | dsnArray := loadDSN() |
| 339 | if len(dsnArray) > 0 { |
| 340 | //Print dsn list |
| 341 | fmt.Printf("Found local stored dsn list: \n") |
| 342 | for i := 0; i < len(dsnArray); i++ { |
| 343 | fmt.Printf("%v: %v\n", i, dsnArray[i]) |
| 344 | } |
| 345 | fmt.Println("Which would you like to connect? (press Enter for default 0):") |
| 346 | |
| 347 | //Read from terminal |
| 348 | reader := bufio.NewReader(os.Stdin) |
| 349 | t, err := reader.ReadString('\n') |
| 350 | t = strings.Trim(t, "\n") |
| 351 | if err != nil { |
| 352 | ConsoleLog.WithError(err).Error("unexpected error") |
| 353 | SetExitStatus(1) |
| 354 | Exit() |
| 355 | } |
| 356 | |
| 357 | var choice int |
| 358 | if t == "" { |
| 359 | choice = 0 |
| 360 | } else { |
| 361 | choice, err = strconv.Atoi(t) |
| 362 | if err != nil || choice >= len(dsnArray) || choice < 0 { |
| 363 | ConsoleLog.Error("invalid choice number") |
| 364 | SetExitStatus(1) |
| 365 | Exit() |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | //Set dsn |
| 370 | dsn = dsnArray[choice] |
| 371 | } else { |
| 372 | ConsoleLog.Error("neither local dsn storage exists nor a dsn string present") |
| 373 | SetExitStatus(1) |
| 374 | printCommandHelp(cmd) |
| 375 | Exit() |
| 376 | } |
| 377 | } |
nothing calls this directly
no test coverage detected