Fix issue with default port in bookmark; cleanup

This commit is contained in:
Dan Sosedoff 2016-11-15 21:58:58 -06:00
parent d74bc06cbd
commit 59018287de
2 changed files with 15 additions and 7 deletions

15
main.go
View File

@ -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 {

View File

@ -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
}