diff --git a/components/ArgConnection.go b/components/ArgConnection.go index a65288d..a09f0f0 100644 --- a/components/ArgConnection.go +++ b/components/ArgConnection.go @@ -1,8 +1,8 @@ package components import ( + "errors" "fmt" - "os" "strings" "github.com/jorgerojas26/lazysql/drivers" @@ -10,11 +10,10 @@ import ( "github.com/jorgerojas26/lazysql/models" ) -func InitFromArg(connectionString string) { +func InitFromArg(connectionString string) error { parsed, err := helpers.ParseConnectionString(connectionString) if err != nil { - fmt.Fprintf(os.Stderr, "Could not parse connection string: %s\n", err) - os.Exit(1) + return errors.New(fmt.Sprintf("Could not parse connection string: %s", err)) } DBName := strings.Split(parsed.Normalize(",", "NULL", 0), ",")[3] @@ -40,8 +39,8 @@ func InitFromArg(connectionString string) { err = newDbDriver.Connect(connection.URL) if err != nil { - fmt.Fprintf(os.Stderr, "Could not connect to database %s: %s\n", connectionString, err) - os.Exit(1) + return errors.New(fmt.Sprintf("Could not connect to database %s: %s", connectionString, err)) } MainPages.AddAndSwitchToPage(connection.URL, NewHomePage(connection, newDbDriver).Flex, true) + return nil } diff --git a/main.go b/main.go index 1df0b01..7f637a6 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "flag" + "fmt" "io" "log" "os" @@ -46,7 +47,11 @@ func main() { fmt.Println("LazySQL version: ", version) os.Exit(0) default: - components.InitFromArg(argsWithProg[1]) + err := components.InitFromArg(argsWithProg[1]) + if err != nil { + fmt.Println(os.Stderr, err) + os.Exit(1) + } } }