Skip to content

Commit 2987b21

Browse files
Akash-Patilravitejag
authored andcommitted
Fixed bugs in add and delete site commands (#30)
1 parent c92a000 commit 2987b21

4 files changed

Lines changed: 57 additions & 1 deletion

File tree

cmd/add/hooks/hooks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func NewHooksCmd() *cobra.Command {
2323
This command adds webhooks which are configured to an App.
2424
`),
2525
Example: heredoc.Doc(`
26-
$ lr adds hooks
26+
$ lr add hooks
2727
2828
Webhook has been added.
2929

cmd/add/site/site.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package site
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
67
"net/http"
78

89
"github.com/MakeNowJust/heredoc"
910
"github.com/loginradius/lr-cli/api"
11+
"github.com/loginradius/lr-cli/cmdutil"
1012
"github.com/loginradius/lr-cli/config"
1113
"github.com/loginradius/lr-cli/request"
1214
"github.com/spf13/cobra"
@@ -16,6 +18,7 @@ var AppName string
1618
var Domain string
1719
var PlanName string
1820
var planOption string
21+
var option string
1922
var AppsInfo *api.CoreAppData
2023

2124
type AddAppResponse struct {
@@ -49,6 +52,15 @@ func addSite() error {
4952
fmt.Println("Please upgrade your plan to add more sites. ")
5053
return nil
5154
}
55+
56+
checkCard, err := cardDetails()
57+
if err != nil {
58+
return err
59+
}
60+
if !checkCard {
61+
return nil
62+
}
63+
5264
checkInput := input()
5365
if !checkInput {
5466
fmt.Println("Please enter the input paramaters properly.")
@@ -112,6 +124,29 @@ func plans() (bool, error) {
112124
return false, nil
113125
}
114126

127+
func cardDetails() (bool, error) {
128+
conf := config.GetInstance()
129+
paymentInfo, err := api.PaymentInfo()
130+
if err != nil {
131+
return false, err
132+
}
133+
paymentMethodId := paymentInfo.Data.Order[0].Paymentdetail.Stripepaymentmethodid
134+
if paymentMethodId == "" {
135+
fmt.Println("Adding more than one app requires valid payment information. Please update card details in dashboard via browser.")
136+
fmt.Println("(Note: User must re-login after updating details in the browser)")
137+
fmt.Printf("Press Y to open Browser window:")
138+
fmt.Scanf("%s", &option)
139+
if option != "Y" {
140+
return false, errors.New("Action not possible without updating card details.")
141+
}
142+
cmdutil.Openbrowser(conf.DashboardDomain + "/apps")
143+
fmt.Println("Please Re-Login via CLI.")
144+
return false, nil
145+
}
146+
return true, nil
147+
148+
}
149+
115150
func add() error {
116151
conf := config.GetInstance()
117152
paymentInfo, err := api.PaymentInfo()

cmd/delete/site/site.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/MakeNowJust/heredoc"
1010
"github.com/loginradius/lr-cli/api"
11+
"github.com/loginradius/lr-cli/cmdutil"
1112
"github.com/loginradius/lr-cli/config"
1213
"github.com/loginradius/lr-cli/request"
1314
"github.com/spf13/cobra"
@@ -101,10 +102,20 @@ func delete(appInfo api.SitesReponse) (bool, error) {
101102
}
102103
var resObj Delete
103104
err = json.Unmarshal(resp, &resObj)
105+
104106
if err != nil {
105107
return false, err
106108
}
109+
107110
if resObj.Isdeleted == true {
111+
err := cmdutil.DeleteFile("siteInfo.json")
112+
if err != nil {
113+
return false, err
114+
}
115+
_, err = api.GetAppsInfo()
116+
if err != nil {
117+
return false, err
118+
}
108119
return true, nil
109120
}
110121
return false, nil

cmdutil/lrUtils.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,13 @@ func DeleteFiles() error {
8888
}
8989
return nil
9090
}
91+
92+
func DeleteFile(filename string) error {
93+
user, _ := user.Current()
94+
fileName := filepath.Join(user.HomeDir, ".lrcli", filename)
95+
err := os.Remove(fileName)
96+
if err != nil {
97+
return err
98+
}
99+
return nil
100+
}

0 commit comments

Comments
 (0)