Skip to content

Commit

Permalink
Merge pull request #74 from cloudflare/jamesog/73-flarectl-fix
Browse files Browse the repository at this point in the history
flarectl: Move api invocation to checkEnv()
  • Loading branch information
jamesog committed May 21, 2016
2 parents 4126653 + 7bbb639 commit 9f46967
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions cmd/flarectl/flarectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,21 @@ func makeTable(zones []table, cols ...string) {
}

func checkEnv() error {
if api == nil {
var err error
api, err = cloudflare.New(os.Getenv("CF_API_KEY"), os.Getenv("CF_API_EMAIL"))
if err != nil {
log.Fatal(err)
}
}

if api.APIKey == "" {
return errors.New("API key not defined")
}
if api.APIEmail == "" {
return errors.New("API email not defined")
}

return nil
}

Expand Down Expand Up @@ -455,12 +464,6 @@ func railgun(*cli.Context) {
}

func main() {
var err error
api, err = cloudflare.New(os.Getenv("CF_API_KEY"), os.Getenv("CF_API_EMAIL"))
if err != nil {
log.Fatal(err)
}

app := cli.NewApp()
app.Name = "flarectl"
app.Usage = "CloudFlare CLI"
Expand Down

0 comments on commit 9f46967

Please sign in to comment.