fbsql disconnect from database with \c - (#2338)

* fbsql disconnect from database with `\c -`

This adds the ability to disconnect from the current database by passing
a hyphen to the `\c` meta-command.

* Update cli/cli.go

Co-authored-by: Matthew Jaffee <jaffee@pilosa.com>

---------

Co-authored-by: Matthew Jaffee <jaffee@pilosa.com>
This commit is contained in:
Travis Turner 2023-03-21 19:21:40 -05:00 committed by GitHub
parent 2f7ae30784
commit 10aab583c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View file

@ -487,7 +487,12 @@ func (cmd *Command) connectToDatabase(dbName string) error {
p = newNopPrinter()
}
if dbName == "" {
// Providing a blank ("") or hyphen ("-") dbName is the equivalent of
// disconnecting from the current database. We support the hyphen option
// because calling the `\c` meta-command without an argument is how you
// print the current connection.
switch dbName {
case "-", "":
cmd.databaseID = ""
cmd.databaseName = ""
p.Printf(cmd.connectionMessage())

View file

@ -43,3 +43,11 @@ EXPECT:executing meta command: meta command 'connect' takes zero or one argument
// Connect to a database.
SEND:\c db1
EXPECTCOMP:WithFormat:You are now connected to database "db1" ({uuid}).
// Disconnect from the current database.
SEND:\c -
EXPECT:You are not connected to a database.
// Connect to a database again.
SEND:\c db1
EXPECTCOMP:WithFormat:You are now connected to database "db1" ({uuid}).