command/meta: add token to client if we have it

This commit is contained in:
Mitchell Hashimoto 2015-03-30 23:10:59 -07:00
parent df4dc88176
commit b2e46896f6
2 changed files with 23 additions and 1 deletions

View File

@ -87,6 +87,9 @@ func (c *AuthCommand) Run(args []string) int {
return 1
}
c.Ui.Output(fmt.Sprintf(
"Successfully authenticated!"))
return 0
}

View File

@ -77,7 +77,26 @@ func (m *Meta) Client() (*api.Client, error) {
config.HttpClient = &client
}
return api.NewClient(config)
// Build the client
client, err := api.NewClient(config)
if err != nil {
return nil, err
}
// If we have a token, then set that
tokenHelper, err := m.TokenHelper()
if err != nil {
return nil, err
}
token, err := tokenHelper.Get()
if err != nil {
return nil, err
}
if token != "" {
client.SetToken(token)
}
return client, nil
}
// Config loads the configuration and returns it. If the configuration