Merge pull request #218 from kpashka/master
Ability to override bookmarks directory + typo fix
This commit is contained in:
commit
a4f2553fbc
2
main.go
2
main.go
@ -60,7 +60,7 @@ func initClient() {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
if options.Bookmark != "" {
|
if options.Bookmark != "" {
|
||||||
cl, err = initClientUsingBookmark(bookmarks.Path(), options.Bookmark)
|
cl, err = initClientUsingBookmark(bookmarks.Path(options.BookmarksDir), options.Bookmark)
|
||||||
} else {
|
} else {
|
||||||
cl, err = client.New()
|
cl, err = client.New()
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 {
|
||||||
path, _ := homedir.Dir()
|
if overrideDir == "" {
|
||||||
return fmt.Sprintf("%s/.pgweb/bookmarks", path)
|
path, _ := homedir.Dir()
|
||||||
|
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) {
|
||||||
|
@ -44,7 +44,7 @@ func Test_Bookmark_URL(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_Bookmarks_Path(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) {
|
func Test_Basename(t *testing.T) {
|
||||||
|
@ -8,25 +8,26 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Version bool `short:"v" long:"version" description:"Print version"`
|
Version bool `short:"v" long:"version" description:"Print version"`
|
||||||
Debug bool `short:"d" long:"debug" description:"Enable debugging mode" default:"false"`
|
Debug bool `short:"d" long:"debug" description:"Enable debugging mode" default:"false"`
|
||||||
Url string `long:"url" description:"Database connection string"`
|
Url string `long:"url" description:"Database connection string"`
|
||||||
Host string `long:"host" description:"Server hostname or IP"`
|
Host string `long:"host" description:"Server hostname or IP"`
|
||||||
Port int `long:"port" description:"Server port" default:"5432"`
|
Port int `long:"port" description:"Server port" default:"5432"`
|
||||||
User string `long:"user" description:"Database user"`
|
User string `long:"user" description:"Database user"`
|
||||||
Pass string `long:"pass" description:"Password for user"`
|
Pass string `long:"pass" description:"Password for user"`
|
||||||
DbName string `long:"db" description:"Database name"`
|
DbName string `long:"db" description:"Database name"`
|
||||||
Ssl string `long:"ssl" description:"SSL option"`
|
Ssl string `long:"ssl" description:"SSL option"`
|
||||||
HttpHost string `long:"bind" description:"HTTP server host" default:"localhost"`
|
HttpHost string `long:"bind" description:"HTTP server host" default:"localhost"`
|
||||||
HttpPort uint `long:"listen" description:"HTTP server listen port" default:"8081"`
|
HttpPort uint `long:"listen" description:"HTTP server listen port" default:"8081"`
|
||||||
AuthUser string `long:"auth-user" description:"HTTP basic auth user"`
|
AuthUser string `long:"auth-user" description:"HTTP basic auth user"`
|
||||||
AuthPass string `long:"auth-pass" description:"HTTP basic auth password"`
|
AuthPass string `long:"auth-pass" description:"HTTP basic auth password"`
|
||||||
SkipOpen bool `short:"s" long:"skip-open" description:"Skip browser open on start"`
|
SkipOpen bool `short:"s" long:"skip-open" description:"Skip browser open on start"`
|
||||||
Sessions bool `long:"sessions" description:"Enable multiple database sessions" default:"false"`
|
Sessions bool `long:"sessions" description:"Enable multiple database sessions" default:"false"`
|
||||||
Prefix string `long:"prefix" description:"Add a url prefix"`
|
Prefix string `long:"prefix" description:"Add a url prefix"`
|
||||||
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user