diff --git a/main.go b/main.go index 7bbc835..828aba8 100644 --- a/main.go +++ b/main.go @@ -30,8 +30,10 @@ func initClientUsingBookmark(bookmarkPath, bookmarkName string) (*client.Client, if err != nil { return nil, err } + opt := bookmark.ConvertToOptions() var connStr string + if opt.Url != "" { // if the bookmark has url set, use it connStr = opt.Url } else { @@ -40,10 +42,12 @@ func initClientUsingBookmark(bookmarkPath, bookmarkName string) (*client.Client, return nil, fmt.Errorf("error building connection string: %v", err) } } + var ssh *shared.SSHInfo if !bookmark.SSHInfoIsEmpty() { ssh = &bookmark.Ssh } + return client.NewFromUrl(connStr, ssh) } @@ -54,16 +58,15 @@ func initClient() { var cl *client.Client var err error + if options.Bookmark != "" { cl, err = initClientUsingBookmark(bookmarks.Path(), options.Bookmark) - if err != nil { - exitWithMessage(err.Error()) - } } else { cl, err = client.New() - if err != nil { - exitWithMessage(err.Error()) - } + } + + if err != nil { + exitWithMessage(err.Error()) } if command.Opts.Debug { diff --git a/pkg/bookmarks/bookmarks.go b/pkg/bookmarks/bookmarks.go index f5d550a..8986288 100644 --- a/pkg/bookmarks/bookmarks.go +++ b/pkg/bookmarks/bookmarks.go @@ -95,10 +95,15 @@ func GetBookmark(bookmarkPath string, bookmarkName string) (Bookmark, error) { if err != nil { return Bookmark{}, err } + bookmark, ok := bookmarks[bookmarkName] if !ok { return Bookmark{}, fmt.Errorf("couldn't find a bookmark with name %s", bookmarkName) } - return bookmark, nil + if bookmark.Port == 0 { + bookmark.Port = 5432 + } + + return bookmark, nil }