Merge pull request #218 from kpashka/master

Ability to override bookmarks directory + typo fix
This commit is contained in:
Dan Sosedoff 2017-01-23 19:25:34 -06:00 committed by GitHub
commit a4f2553fbc
5 changed files with 31 additions and 26 deletions

View File

@ -60,7 +60,7 @@ func initClient() {
var err error
if options.Bookmark != "" {
cl, err = initClientUsingBookmark(bookmarks.Path(), options.Bookmark)
cl, err = initClientUsingBookmark(bookmarks.Path(options.BookmarksDir), options.Bookmark)
} else {
cl, err = client.New()
}

View File

@ -376,7 +376,7 @@ func HandleQuery(query string, c *gin.Context) {
case "csv":
c.Data(200, "text/csv", result.CSV())
case "json":
c.Data(200, "applicaiton/json", result.JSON())
c.Data(200, "application/json", result.JSON())
case "xml":
c.XML(200, result)
default:
@ -385,7 +385,7 @@ func HandleQuery(query string, c *gin.Context) {
}
func GetBookmarks(c *gin.Context) {
bookmarks, err := bookmarks.ReadAll(bookmarks.Path())
bookmarks, err := bookmarks.ReadAll(bookmarks.Path(command.Opts.BookmarksDir))
serveResult(bookmarks, err, c)
}

View File

@ -62,11 +62,15 @@ func fileBasename(path string) string {
return strings.Replace(filename, filepath.Ext(path), "", 1)
}
func Path() string {
func Path(overrideDir string) string {
if overrideDir == "" {
path, _ := homedir.Dir()
return fmt.Sprintf("%s/.pgweb/bookmarks", path)
}
return overrideDir
}
func ReadAll(path string) (map[string]Bookmark, error) {
results := map[string]Bookmark{}

View File

@ -44,7 +44,7 @@ func Test_Bookmark_URL(t *testing.T) {
}
func Test_Bookmarks_Path(t *testing.T) {
assert.NotEqual(t, "/.pgweb/bookmarks", Path())
assert.NotEqual(t, "/.pgweb/bookmarks", Path(""))
}
func Test_Basename(t *testing.T) {

View File

@ -27,6 +27,7 @@ type Options struct {
ReadOnly bool `long:"readonly" description:"Run database connection in readonly mode"`
LockSession bool `long:"lock-session" description:"Lock session to a single database connection" default:"false"`
Bookmark string `short:"b" long:"bookmark" description:"Bookmark to use for connection. Bookmark files are stored under $HOME/.pgweb/bookmarks/*.toml" default:""`
BookmarksDir string `long:"bookmarks-dir" description:"Overrides default directory for bookmark files to search" default:""`
}
var Opts Options