Skip to content

Commit 4e9a509

Browse files
Akash-Patilmohammed786
authored andcommitted
Implemented Prompt feature for CLI, for selecting the options
1 parent 45fbf60 commit 4e9a509

16 files changed

Lines changed: 399 additions & 309 deletions

File tree

api/platformConfiguration.go

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"net/http"
66

7-
"github.com/loginradius/lr-cli/config"
87
"github.com/loginradius/lr-cli/request"
98
)
109

@@ -28,79 +27,76 @@ type FieldTypeConfig struct {
2827
}
2928

3029
var TypeMap = map[int]FieldTypeConfig{
31-
1: {
30+
0: {
3231
Name: "String",
3332
ShouldDisplayValidaitonRuleInput: true,
3433
ShouldShowOption: false,
3534
},
36-
2: {
35+
1: {
3736
Name: "CheckBox",
3837
ShouldDisplayValidaitonRuleInput: false,
3938
ShouldShowOption: false,
4039
},
41-
3: {
40+
2: {
4241
Name: "Option",
4342
ShouldDisplayValidaitonRuleInput: false,
4443
ShouldShowOption: true,
4544
},
46-
4: {
45+
3: {
4746
Name: "Password",
4847
ShouldDisplayValidaitonRuleInput: true,
4948
ShouldShowOption: false,
5049
},
51-
5: {
50+
4: {
5251
Name: "Hidden",
5352
ShouldDisplayValidaitonRuleInput: true,
5453
ShouldShowOption: false,
5554
},
56-
6: {
55+
5: {
5756
Name: "Email",
5857
ShouldDisplayValidaitonRuleInput: true,
5958
ShouldShowOption: false,
6059
},
61-
7: {
60+
6: {
6261
Name: "Text",
6362
ShouldDisplayValidaitonRuleInput: true,
6463
ShouldShowOption: false,
6564
},
6665
}
6766

6867
type Schema struct {
69-
Display string `json:"Display"`
70-
Enabled bool `json:"Enabled"`
71-
IsMandatory bool `json:"IsMandatory"`
72-
Parent string `json:"Parent"`
73-
ParentDataSource string `json:"ParentDataSource"`
74-
Permission string `json:"Permission"`
75-
Name string `json:"name"`
76-
Options []Array `json:"options"`
77-
Rules string `json:"rules"`
78-
Status string `json:"status"`
79-
Type string `json:"type"`
68+
Display string `json:"Display"`
69+
Enabled bool `json:"Enabled"`
70+
IsMandatory bool `json:"IsMandatory"`
71+
Parent string `json:"Parent"`
72+
ParentDataSource string `json:"ParentDataSource"`
73+
Permission string `json:"Permission"`
74+
Name string `json:"name"`
75+
Options []OptSchema `json:"options"`
76+
Rules string `json:"rules"`
77+
Status string `json:"status"`
78+
Type string `json:"type"`
8079
}
81-
type Array struct {
80+
type OptSchema struct {
8281
Value string `json:"value"`
8382
Text string `json:"text"`
8483
}
8584

86-
var Url string
87-
88-
type ResultResp struct {
85+
type StandardFields struct {
8986
Data []Schema `json:"Data"`
9087
}
9188

92-
func GetFields(tem string) (*ResultResp, error) {
93-
conf := config.GetInstance()
94-
if tem == "active" {
95-
Url = conf.AdminConsoleAPIDomain + "/platform-configuration/registration-form-settings?"
89+
func GetStandardFields(ftype string) (*StandardFields, error) {
90+
var url string
91+
if ftype == "active" {
92+
url = conf.AdminConsoleAPIDomain + "/platform-configuration/registration-form-settings?"
9693
}
97-
if tem == "all" {
98-
Url = conf.AdminConsoleAPIDomain + "/platform-configuration/platform-registration-fields?"
94+
if ftype == "all" {
95+
url = conf.AdminConsoleAPIDomain + "/platform-configuration/platform-registration-fields?"
9996
}
10097

101-
var resultResp ResultResp
102-
resp, err := request.Rest(http.MethodGet, Url, nil, "")
103-
98+
var resultResp StandardFields
99+
resp, err := request.Rest(http.MethodGet, url, nil, "")
104100
if err != nil {
105101
return nil, err
106102
}
@@ -109,14 +105,24 @@ func GetFields(tem string) (*ResultResp, error) {
109105
if err != nil {
110106
return nil, err
111107
}
108+
109+
if ftype == "all" {
110+
var basicFields StandardFields
111+
for i := 0; i < len(resultResp.Data); i++ {
112+
if resultResp.Data[i].Parent == "" {
113+
basicFields.Data = append(basicFields.Data, resultResp.Data[i])
114+
}
115+
}
116+
return &basicFields, nil
117+
}
112118
return &resultResp, nil
113119
}
120+
114121
func GetActiveProviders() (*ProviderList, error) {
115-
conf := config.GetInstance()
116-
Url = conf.AdminConsoleAPIDomain + "/platform-configuration/social-providers/options?"
122+
url := conf.AdminConsoleAPIDomain + "/platform-configuration/social-providers/options?"
117123

118124
var R1 ProviderList
119-
resp, err := request.Rest(http.MethodGet, Url, nil, "")
125+
resp, err := request.Rest(http.MethodGet, url, nil, "")
120126

121127
if err != nil {
122128
return nil, err

cmd/add/hooks/hooks.go

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import (
55
"fmt"
66
"net/http"
77

8+
"github.com/AlecAivazis/survey/v2"
89
"github.com/MakeNowJust/heredoc"
910
"github.com/loginradius/lr-cli/api"
11+
"github.com/loginradius/lr-cli/prompt"
1012
"github.com/spf13/cobra"
1113
)
1214

@@ -23,10 +25,15 @@ func NewHooksCmd() *cobra.Command {
2325
This command adds webhooks which are configured to an App.
2426
`),
2527
Example: heredoc.Doc(`
26-
$ lr add hooks
27-
28+
$ lr add hooks
29+
Enter Name: <hook-name>
30+
? Select a plan [Use arrows to move, type to filter]
31+
> Login
32+
Register
33+
ResetPassword
34+
UpdateProfile
35+
Enter TargetUrl: <url>
2836
Webhook has been added.
29-
3037
`),
3138
RunE: func(cmd *cobra.Command, args []string) error {
3239
return addHooks()
@@ -62,30 +69,30 @@ func input() bool {
6269
fmt.Println("Name is a required entry")
6370
return false
6471
}
65-
event := map[string]string{
66-
"1": "Login",
67-
"2": "Register",
68-
"3": "ResetPassword",
69-
"4": "UpdateProfile",
72+
event := map[int]string{
73+
0: "Login",
74+
1: "Register",
75+
2: "ResetPassword",
76+
3: "UpdateProfile",
7077
}
7178

7279
//Currently supports only Developer plan event options.
73-
fmt.Println("To select an Event, choose a correponding number from the following options: ")
74-
fmt.Println("1 - Login")
75-
fmt.Println("2 - Register")
76-
fmt.Println("3 - ResetPassword")
77-
fmt.Println("4 - UpdateProfile")
78-
fmt.Printf("Option: ")
79-
fmt.Scanf("%s\n", &eventOption)
80-
if eventOption == "" {
81-
fmt.Println("Event is a required entry")
82-
return false
83-
}
84-
Event = event[eventOption]
85-
if Event == "" {
86-
fmt.Println("Invalid Choice of Event")
80+
var eventChoice int
81+
err := prompt.SurveyAskOne(&survey.Select{
82+
Message: "Select a plan",
83+
Options: []string{
84+
"Login",
85+
"Register",
86+
"ResetPassword",
87+
"UpdateProfile",
88+
},
89+
}, &eventChoice)
90+
if err != nil {
8791
return false
8892
}
93+
94+
Event = event[eventChoice]
95+
8996
fmt.Printf("Enter TargetUrl: ")
9097
fmt.Scanf("%s\n", &TargetUrl)
9198
if TargetUrl == "" {

0 commit comments

Comments
 (0)