Skip to content

Commit

Permalink
Fix bug (all pathes are available)
Browse files Browse the repository at this point in the history
  • Loading branch information
babarot committed Nov 21, 2017
1 parent 7f80900 commit c283339
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 9 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
neturl "net/url"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -81,13 +82,17 @@ func (cfg *Config) LoadFile(file string) error {
return json.NewEncoder(f).Encode(cfg)
}

func (cfg *Config) GetEnv(url string) (env Env) {
func (cfg *Config) GetEnv(url string) (env Env, err error) {
u, err := neturl.Parse(url)
if err != nil {
return
}
for _, service := range cfg.Services {
if strings.Contains(service.URL, url) {
return service.Env
if strings.Contains(service.URL, u.Host) {
return service.Env, nil
}
}
return env
return
}

func (cfg *Config) GetURLs() (list []string) {
Expand Down
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ func run(args []string) int {
return 1
}

env := cfg.GetEnv(args[0])
env, err := cfg.GetEnv(args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err.Error())
return 1
}
if credentials == "" {
credentials = env.Credentials
}
Expand Down

0 comments on commit c283339

Please sign in to comment.