Ability to override bookmarks directory

This commit is contained in:
Pavel Kiselev 2017-01-24 07:55:18 +07:00
parent f6f40ab707
commit 9b1d915dd1
No known key found for this signature in database
GPG Key ID: 4964A418B307836D
3 changed files with 29 additions and 24 deletions

View File

@ -376,7 +376,7 @@ func HandleQuery(query string, c *gin.Context) {
case "csv": case "csv":
c.Data(200, "text/csv", result.CSV()) c.Data(200, "text/csv", result.CSV())
case "json": case "json":
c.Data(200, "applicaiton/json", result.JSON()) c.Data(200, "application/json", result.JSON())
case "xml": case "xml":
c.XML(200, result) c.XML(200, result)
default: default:
@ -385,7 +385,7 @@ func HandleQuery(query string, c *gin.Context) {
} }
func GetBookmarks(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) serveResult(bookmarks, err, c)
} }

View File

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

View File

@ -27,6 +27,7 @@ type Options struct {
ReadOnly bool `long:"readonly" description:"Run database connection in readonly mode"` 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"` 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:""` 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 var Opts Options