From b676dfe597f3c02b0d09c7bc58a68b334aa58064 Mon Sep 17 00:00:00 2001 From: KeisukeYamashita <19yamashita15@gmail.com> Date: Mon, 7 Oct 2019 15:48:07 +0900 Subject: [PATCH] :wrench: fix alias nil pointer --- providers/gcp/gcp.go | 2 +- providers/github/github.go | 18 ++++++++++++++++++ providers/google/google.go | 2 +- providers/pagerduty/pagerduty.go | 2 +- providers/youtube/youtube.go | 16 ++++++++++++++++ 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/providers/gcp/gcp.go b/providers/gcp/gcp.go index 5615417..4569ef4 100644 --- a/providers/gcp/gcp.go +++ b/providers/gcp/gcp.go @@ -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 "" } diff --git a/providers/github/github.go b/providers/github/github.go index cad73f7..243240b 100644 --- a/providers/github/github.go +++ b/providers/github/github.go @@ -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 ... @@ -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 diff --git a/providers/google/google.go b/providers/google/google.go index 29d2077..7b30365 100644 --- a/providers/google/google.go +++ b/providers/google/google.go @@ -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 "" } diff --git a/providers/pagerduty/pagerduty.go b/providers/pagerduty/pagerduty.go index dc50542..c333820 100644 --- a/providers/pagerduty/pagerduty.go +++ b/providers/pagerduty/pagerduty.go @@ -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 "" } diff --git a/providers/youtube/youtube.go b/providers/youtube/youtube.go index b22a3d1..0c7486a 100644 --- a/providers/youtube/youtube.go +++ b/providers/youtube/youtube.go @@ -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