diff --git a/cli/elastic-thought/main.go b/cli/elastic-thought/main.go index a1a0997..cde61c0 100644 --- a/cli/elastic-thought/main.go +++ b/cli/elastic-thought/main.go @@ -2,7 +2,10 @@ package main import ( + "fmt" + "github.com/couchbaselabs/logg" + "github.com/docopt/docopt-go" "github.com/gin-gonic/gin" et "github.com/tleyden/elastic-thought" ) @@ -13,8 +16,25 @@ func init() { func main() { + usage := `ElasticThought REST API server. + +Usage: + elastic-thought [--sync-gw-url=] [--blob-store-url=] + +Options: + -h --help Show this screen. + --sync-gw-url= Sync Gateway DB URL [default: http://localhost:4985/elastic-thought]. + --blob-store-url= Blob store URL [default: file:///tmp].` + + parsedDocOptArgs, _ := docopt.Parse(usage, nil, true, "ElasticThought alpha", false) + fmt.Println(parsedDocOptArgs) + config := *(et.NewDefaultConfiguration()) // TODO: get these vals from cmd line args + // parse command line args into struct + + // config = config.Merge(parsedDocOptArgs) + if err := et.EnvironmentSanityCheck(config); err != nil { logg.LogFatal("Failed environment sanity check: %v", err) return diff --git a/configuration.go b/configuration.go index c965c26..4b2564a 100644 --- a/configuration.go +++ b/configuration.go @@ -57,3 +57,26 @@ func (c Configuration) DbConnection() couch.Database { func (c Configuration) NewBlobStoreClient() (BlobStore, error) { return NewBlobStore(c.CbfsUrl) } + +// Add values from parsedDocOpts into Configuration and return a new instance +// Example map: +// map[--help:false --blob-store-url:file:///tmp --sync-gw-url:http://blah.com:4985/et] +func (c Configuration) Merge(parsedDocOpts map[string]interface{}) (Configuration, error) { + + // Sync Gateway URL + syncGwUrl, ok := parsedDocOpts["--sync-gw-url"].(string) + if !ok { + return c, fmt.Errorf("Expected string arg in --sync-gw-url, got %T", syncGwUrl) + } + c.DbUrl = syncGwUrl + + // Blob Store URL + blobStoreUrl, ok := parsedDocOpts["--blob-store-url"].(string) + if !ok { + return c, fmt.Errorf("Expected string arg in --blob-store-url, got %T", blobStoreUrl) + } + c.CbfsUrl = blobStoreUrl + + return c, nil + +}