Skip to content

Commit

Permalink
Correctly read device name and profile for listen and http requests (#86
Browse files Browse the repository at this point in the history
)

* Correctly read device name and profile for listen and http requests

* Remove extra println
  • Loading branch information
tomer-stripe committed Aug 8, 2019
1 parent 2ffb75c commit b489043
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func newDeleteCmd() *deleteCmd {
gc := &deleteCmd{}

gc.reqs.Method = http.MethodDelete
gc.reqs.Profile = Config.Profile
gc.reqs.Profile = &Config.Profile
gc.reqs.Cmd = &cobra.Command{
Use: "delete",
Args: validators.ExactArgs(1),
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func newGetCmd() *getCmd {
gc := &getCmd{}

gc.reqs.Method = http.MethodGet
gc.reqs.Profile = Config.Profile
gc.reqs.Profile = &Config.Profile
gc.reqs.Cmd = &cobra.Command{
Use: "get",
Args: validators.ExactArgs(1),
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func newPostCmd() *postCmd {
gc := &postCmd{}

gc.reqs.Method = http.MethodPost
gc.reqs.Profile = Config.Profile
gc.reqs.Profile = &Config.Profile
gc.reqs.Cmd = &cobra.Command{
Use: "post",
Args: validators.ExactArgs(1),
Expand Down
7 changes: 6 additions & 1 deletion pkg/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ func (p *Profile) CreateProfile() error {

// GetDeviceName returns the configured device name
func (p *Profile) GetDeviceName() (string, error) {
deviceName := viper.GetString("device_name")
if deviceName != "" {
return deviceName, nil
}

if err := viper.ReadInConfig(); err == nil {
return viper.GetString("default.device_name"), nil
return viper.GetString(p.GetConfigField("device_name")), nil
}

return "", errors.New("your device name has not been configured. Use `stripe login` to set your device name")
Expand Down
2 changes: 1 addition & 1 deletion pkg/requests/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Base struct {
Cmd *cobra.Command

Method string
Profile config.Profile
Profile *config.Profile

Parameters RequestParameters

Expand Down
4 changes: 2 additions & 2 deletions pkg/requests/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (ex *Examples) buildRequest(method string, data []string) (*Base, *RequestP
}

base := &Base{
Profile: ex.Profile,
Profile: &ex.Profile,
Method: method,
SuppressOutput: true,
APIBaseURL: ex.APIBaseURL,
Expand Down Expand Up @@ -472,7 +472,7 @@ func (ex *Examples) WebhookEndpointsList() WebhookEndpointList {
}

base := &Base{
Profile: ex.Profile,
Profile: &ex.Profile,
Method: http.MethodGet,
SuppressOutput: true,
}
Expand Down

0 comments on commit b489043

Please sign in to comment.