Skip to content

Commit bdf9d10

Browse files
fix(cli): add --header flag to all CLI subcommands
1 parent 789e0b7 commit bdf9d10

8 files changed

Lines changed: 181 additions & 53 deletions

File tree

cmd/group.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"os"
66

7-
"connectrpc.com/connect"
87
"github.com/MakeNowJust/heredoc"
98
"github.com/raystack/frontier/pkg/file"
109
frontierv1beta1 "github.com/raystack/frontier/proto/v1beta1"
@@ -100,7 +99,7 @@ func createGroupCommand(cliConfig *Config) *cli.Command {
10099
}
101100

102101
func editGroupCommand(cliConfig *Config) *cli.Command {
103-
var filePath string
102+
var filePath, header string
104103

105104
cmd := &cli.Command{
106105
Use: "edit",
@@ -132,10 +131,14 @@ func editGroupCommand(cliConfig *Config) *cli.Command {
132131
}
133132

134133
groupID := args[0]
135-
_, err = client.UpdateGroup(cmd.Context(), connect.NewRequest(&frontierv1beta1.UpdateGroupRequest{
134+
req, err := newRequest(&frontierv1beta1.UpdateGroupRequest{
136135
Id: groupID,
137136
Body: &reqBody,
138-
}))
137+
}, header)
138+
if err != nil {
139+
return err
140+
}
141+
_, err = client.UpdateGroup(cmd.Context(), req)
139142
if err != nil {
140143
return err
141144
}
@@ -148,12 +151,14 @@ func editGroupCommand(cliConfig *Config) *cli.Command {
148151

149152
cmd.Flags().StringVarP(&filePath, "file", "f", "", "Path to the group body file")
150153
cmd.MarkFlagRequired("file")
154+
cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
151155

152156
return cmd
153157
}
154158

155159
func viewGroupCommand(cliConfig *Config) *cli.Command {
156160
var metadata bool
161+
var header string
157162

158163
cmd := &cli.Command{
159164
Use: "view",
@@ -176,10 +181,14 @@ func viewGroupCommand(cliConfig *Config) *cli.Command {
176181

177182
orgID := args[0]
178183
groupID := args[1]
179-
res, err := client.GetGroup(cmd.Context(), connect.NewRequest(&frontierv1beta1.GetGroupRequest{
184+
req, err := newRequest(&frontierv1beta1.GetGroupRequest{
180185
Id: groupID,
181186
OrgId: orgID,
182-
}))
187+
}, header)
188+
if err != nil {
189+
return err
190+
}
191+
res, err := client.GetGroup(cmd.Context(), req)
183192
if err != nil {
184193
return err
185194
}
@@ -220,11 +229,13 @@ func viewGroupCommand(cliConfig *Config) *cli.Command {
220229
}
221230

222231
cmd.Flags().BoolVarP(&metadata, "metadata", "m", false, "Set this flag to see metadata")
232+
cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
223233

224234
return cmd
225235
}
226236

227237
func listGroupCommand(cliConfig *Config) *cli.Command {
238+
var header string
228239
cmd := &cli.Command{
229240
Use: "list",
230241
Short: "List all groups",
@@ -244,9 +255,13 @@ func listGroupCommand(cliConfig *Config) *cli.Command {
244255
return err
245256
}
246257

247-
res, err := client.ListOrganizationGroups(cmd.Context(), connect.NewRequest(&frontierv1beta1.ListOrganizationGroupsRequest{
258+
req, err := newRequest(&frontierv1beta1.ListOrganizationGroupsRequest{
248259
OrgId: args[0],
249-
}))
260+
}, header)
261+
if err != nil {
262+
return err
263+
}
264+
res, err := client.ListOrganizationGroups(cmd.Context(), req)
250265
if err != nil {
251266
return err
252267
}
@@ -277,5 +292,7 @@ func listGroupCommand(cliConfig *Config) *cli.Command {
277292
},
278293
}
279294

295+
cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
296+
280297
return cmd
281298
}

cmd/namespace.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"os"
66

7-
"connectrpc.com/connect"
87
"github.com/MakeNowJust/heredoc"
98
frontierv1beta1 "github.com/raystack/frontier/proto/v1beta1"
109
"github.com/raystack/salt/cli/printer"
@@ -38,6 +37,7 @@ func NamespaceCommand(cliConfig *Config) *cli.Command {
3837
}
3938

4039
func viewNamespaceCommand(cliConfig *Config) *cli.Command {
40+
var header string
4141
cmd := &cli.Command{
4242
Use: "view",
4343
Short: "View a namespace",
@@ -58,9 +58,13 @@ func viewNamespaceCommand(cliConfig *Config) *cli.Command {
5858
}
5959

6060
namespaceID := args[0]
61-
res, err := client.GetNamespace(cmd.Context(), connect.NewRequest(&frontierv1beta1.GetNamespaceRequest{
61+
req, err := newRequest(&frontierv1beta1.GetNamespaceRequest{
6262
Id: namespaceID,
63-
}))
63+
}, header)
64+
if err != nil {
65+
return err
66+
}
67+
res, err := client.GetNamespace(cmd.Context(), req)
6468
if err != nil {
6569
return err
6670
}
@@ -84,10 +88,13 @@ func viewNamespaceCommand(cliConfig *Config) *cli.Command {
8488
},
8589
}
8690

91+
cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
92+
8793
return cmd
8894
}
8995

9096
func listNamespaceCommand(cliConfig *Config) *cli.Command {
97+
var header string
9198
cmd := &cli.Command{
9299
Use: "list",
93100
Short: "List all namespaces",
@@ -107,7 +114,11 @@ func listNamespaceCommand(cliConfig *Config) *cli.Command {
107114
return err
108115
}
109116

110-
res, err := client.ListNamespaces(cmd.Context(), connect.NewRequest(&frontierv1beta1.ListNamespacesRequest{}))
117+
req, err := newRequest(&frontierv1beta1.ListNamespacesRequest{}, header)
118+
if err != nil {
119+
return err
120+
}
121+
res, err := client.ListNamespaces(cmd.Context(), req)
111122
if err != nil {
112123
return err
113124
}
@@ -134,5 +145,7 @@ func listNamespaceCommand(cliConfig *Config) *cli.Command {
134145
},
135146
}
136147

148+
cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
149+
137150
return cmd
138151
}

cmd/organization.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func createOrganizationCommand(cliConfig *Config) *cli.Command {
101101
}
102102

103103
func editOrganizationCommand(cliConfig *Config) *cli.Command {
104-
var filePath string
104+
var filePath, header string
105105

106106
cmd := &cli.Command{
107107
Use: "edit",
@@ -133,10 +133,14 @@ func editOrganizationCommand(cliConfig *Config) *cli.Command {
133133
}
134134

135135
organizationID := args[0]
136-
_, err = client.UpdateOrganization(cmd.Context(), connect.NewRequest(&frontierv1beta1.UpdateOrganizationRequest{
136+
req, err := newRequest(&frontierv1beta1.UpdateOrganizationRequest{
137137
Id: organizationID,
138138
Body: &reqBody,
139-
}))
139+
}, header)
140+
if err != nil {
141+
return err
142+
}
143+
_, err = client.UpdateOrganization(cmd.Context(), req)
140144
if err != nil {
141145
return err
142146
}
@@ -149,12 +153,14 @@ func editOrganizationCommand(cliConfig *Config) *cli.Command {
149153

150154
cmd.Flags().StringVarP(&filePath, "file", "f", "", "Path to the organization body file")
151155
cmd.MarkFlagRequired("file")
156+
cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
152157

153158
return cmd
154159
}
155160

156161
func viewOrganizationCommand(cliConfig *Config) *cli.Command {
157162
var metadata bool
163+
var header string
158164

159165
cmd := &cli.Command{
160166
Use: "view",
@@ -176,9 +182,13 @@ func viewOrganizationCommand(cliConfig *Config) *cli.Command {
176182
}
177183

178184
organizationID := args[0]
179-
res, err := client.GetOrganization(cmd.Context(), connect.NewRequest(&frontierv1beta1.GetOrganizationRequest{
185+
req, err := newRequest(&frontierv1beta1.GetOrganizationRequest{
180186
Id: organizationID,
181-
}))
187+
}, header)
188+
if err != nil {
189+
return err
190+
}
191+
res, err := client.GetOrganization(cmd.Context(), req)
182192
if err != nil {
183193
return err
184194
}
@@ -218,11 +228,13 @@ func viewOrganizationCommand(cliConfig *Config) *cli.Command {
218228
}
219229

220230
cmd.Flags().BoolVarP(&metadata, "metadata", "m", false, "Set this flag to see metadata")
231+
cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
221232

222233
return cmd
223234
}
224235

225236
func listOrganizationCommand(cliConfig *Config) *cli.Command {
237+
var header string
226238
cmd := &cli.Command{
227239
Use: "list",
228240
Short: "List all organizations",
@@ -242,7 +254,11 @@ func listOrganizationCommand(cliConfig *Config) *cli.Command {
242254
return err
243255
}
244256

245-
res, err := client.ListOrganizations(cmd.Context(), connect.NewRequest(&frontierv1beta1.ListOrganizationsRequest{}))
257+
req, err := newRequest(&frontierv1beta1.ListOrganizationsRequest{}, header)
258+
if err != nil {
259+
return err
260+
}
261+
res, err := client.ListOrganizations(cmd.Context(), req)
246262
if err != nil {
247263
return err
248264
}
@@ -272,6 +288,8 @@ func listOrganizationCommand(cliConfig *Config) *cli.Command {
272288
},
273289
}
274290

291+
cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
292+
275293
return cmd
276294
}
277295

cmd/permission.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"os"
66

7-
"connectrpc.com/connect"
87
"github.com/MakeNowJust/heredoc"
98
"github.com/raystack/frontier/pkg/file"
109
frontierv1beta1 "github.com/raystack/frontier/proto/v1beta1"
@@ -100,7 +99,7 @@ func createPermissionCommand(cliConfig *Config) *cli.Command {
10099
}
101100

102101
func editPermissionCommand(cliConfig *Config) *cli.Command {
103-
var filePath string
102+
var filePath, header string
104103

105104
cmd := &cli.Command{
106105
Use: "edit",
@@ -132,10 +131,14 @@ func editPermissionCommand(cliConfig *Config) *cli.Command {
132131
}
133132

134133
permissionID := args[0]
135-
_, err = client.UpdatePermission(cmd.Context(), connect.NewRequest(&frontierv1beta1.UpdatePermissionRequest{
134+
req, err := newRequest(&frontierv1beta1.UpdatePermissionRequest{
136135
Id: permissionID,
137136
Body: &reqBody,
138-
}))
137+
}, header)
138+
if err != nil {
139+
return err
140+
}
141+
_, err = client.UpdatePermission(cmd.Context(), req)
139142
if err != nil {
140143
return err
141144
}
@@ -148,11 +151,13 @@ func editPermissionCommand(cliConfig *Config) *cli.Command {
148151

149152
cmd.Flags().StringVarP(&filePath, "file", "f", "", "Path to the permission body file")
150153
cmd.MarkFlagRequired("file")
154+
cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
151155

152156
return cmd
153157
}
154158

155159
func viewPermissionCommand(cliConfig *Config) *cli.Command {
160+
var header string
156161
cmd := &cli.Command{
157162
Use: "view",
158163
Short: "View a permission",
@@ -173,9 +178,13 @@ func viewPermissionCommand(cliConfig *Config) *cli.Command {
173178
}
174179

175180
permissionID := args[0]
176-
res, err := client.GetPermission(cmd.Context(), connect.NewRequest(&frontierv1beta1.GetPermissionRequest{
181+
req, err := newRequest(&frontierv1beta1.GetPermissionRequest{
177182
Id: permissionID,
178-
}))
183+
}, header)
184+
if err != nil {
185+
return err
186+
}
187+
res, err := client.GetPermission(cmd.Context(), req)
179188
if err != nil {
180189
return err
181190
}
@@ -198,10 +207,13 @@ func viewPermissionCommand(cliConfig *Config) *cli.Command {
198207
},
199208
}
200209

210+
cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
211+
201212
return cmd
202213
}
203214

204215
func listPermissionCommand(cliConfig *Config) *cli.Command {
216+
var header string
205217
cmd := &cli.Command{
206218
Use: "list",
207219
Short: "List all permissions",
@@ -221,7 +233,11 @@ func listPermissionCommand(cliConfig *Config) *cli.Command {
221233
return err
222234
}
223235

224-
res, err := client.ListPermissions(cmd.Context(), connect.NewRequest(&frontierv1beta1.ListPermissionsRequest{}))
236+
req, err := newRequest(&frontierv1beta1.ListPermissionsRequest{}, header)
237+
if err != nil {
238+
return err
239+
}
240+
res, err := client.ListPermissions(cmd.Context(), req)
225241
if err != nil {
226242
return err
227243
}
@@ -252,5 +268,7 @@ func listPermissionCommand(cliConfig *Config) *cli.Command {
252268
},
253269
}
254270

271+
cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
272+
255273
return cmd
256274
}

0 commit comments

Comments
 (0)