Skip to content

Commit

Permalink
Merge pull request #27 from KeisukeYamashita/fix-alias-nil-pointer
Browse files Browse the repository at this point in the history
Fix alias nil pointer
  • Loading branch information
KeisukeYamashita authored Oct 7, 2019
2 parents b9335ce + b676dfe commit 18e169d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion providers/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (p *Provider) addProjectParam() {

// GetCtxString ...
func (p *Provider) GetCtxString(str string) string {
key := p.GetCtxString(str)
key := p.Ctx.String(str)
if key == "" {
return ""
}
Expand Down
18 changes: 18 additions & 0 deletions providers/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"github.com/urfave/cli"
)

// Provider ...
type Provider struct {
baseURL *url.URL
URL *url.URL
Ctx *cli.Context
Aliases map[string]interface{}
}

// Init ...
Expand Down Expand Up @@ -47,6 +49,22 @@ func (p *Provider) addProductPath(product string) {
}
}

// GetCtxString ...
func (p *Provider) GetCtxString(str string) string {
key := p.Ctx.String(str)
if key == "" {
return ""
}
value, ok := p.Aliases[key].(string)
if !ok {
return key
}
if value == "" {
return key
}
return value
}

func (p *Provider) join(additionPath string) {
if p.URL == nil {
p.URL = p.baseURL
Expand Down
2 changes: 1 addition & 1 deletion providers/google/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (p *Provider) join(additionPath string) {

// GetCtxString ...
func (p *Provider) GetCtxString(str string) string {
key := p.GetCtxString(str)
key := p.Ctx.String(str)
if key == "" {
return ""
}
Expand Down
2 changes: 1 addition & 1 deletion providers/pagerduty/pagerduty.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (p *Provider) join(additionPath string) {

// GetCtxString ...
func (p *Provider) GetCtxString(str string) string {
key := p.GetCtxString(str)
key := p.Ctx.String(str)
if key == "" {
return ""
}
Expand Down
16 changes: 16 additions & 0 deletions providers/youtube/youtube.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ func (p *Provider) addProductPath(product string) {
}
}

// GetCtxString ...
func (p *Provider) GetCtxString(str string) string {
key := p.Ctx.String(str)
if key == "" {
return ""
}
value, ok := p.Aliases[key].(string)
if !ok {
return key
}
if value == "" {
return key
}
return value
}

func (p *Provider) join(additionPath string) {
if p.URL == nil {
p.URL = p.baseURL
Expand Down

0 comments on commit 18e169d

Please sign in to comment.