Skip to content

fix(cli): add --header flag to all CLI subcommands#1444

Open
capable-average wants to merge 2 commits intoraystack:mainfrom
capable-average:fix/add-header-flag-in-cli-subcommands
Open

fix(cli): add --header flag to all CLI subcommands#1444
capable-average wants to merge 2 commits intoraystack:mainfrom
capable-average:fix/add-header-flag-in-cli-subcommands

Conversation

@capable-average
Copy link

Summary

  • Added --header / -H flag in all missing CLI subcommands
  • All affected subcommands now use the newRequest helper

Test Plan

  • Manual testing completed
  • Build and type checking passes

@vercel
Copy link

vercel bot commented Mar 10, 2026

@capable-average is attempting to deploy a commit to the Raystack Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added a --header / -H flag to create, edit, view, and list commands for groups, namespaces, organizations (create now requires a header), permissions, policies, projects, roles, and users — allowing callers to supply custom HTTP headers with requests.

Walkthrough

Replaces inline connect.NewRequest calls with a newRequest(..., header) helper and adds a --header / -H flag, threading header support through create/edit/view/list CLI commands and passing constructed requests to RPC client calls. Removes direct connect imports.

Changes

Cohort / File(s) Summary
CLI commands — header wiring & request helper
cmd/group.go, cmd/namespace.go, cmd/organization.go, cmd/permission.go, cmd/policy.go, cmd/project.go, cmd/role.go, cmd/user.go
Added --header / -H flags and local header variables; replaced direct connect.NewRequest usage with newRequest(..., header) across create/edit/view/list flows; return immediately on newRequest errors; updated client call sites to use returned request objects; removed connect imports.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • rohilsurana

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@capable-average
Copy link
Author

closes #1392

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cmd/organization.go (1)

296-346: ⚠️ Potential issue | 🟡 Minor

Missing header flag in admlistOrganizationCommand.

This command still uses connect.NewRequest directly (line 317) and lacks the --header flag. Per the PR objective to "add --header flag to all CLI subcommands," this command should also be refactored to use the newRequest helper with header support.

🔧 Proposed fix to add header support
 func admlistOrganizationCommand(cliConfig *Config) *cli.Command {
+	var header string
 	cmd := &cli.Command{
 		Use:   "admlist",
 		Short: "list admins of an organization",
@@ ... @@
 			organizationID := args[0]
-			res, err := client.ListOrganizationAdmins(cmd.Context(), connect.NewRequest(&frontierv1beta1.ListOrganizationAdminsRequest{
+			req, err := newRequest(&frontierv1beta1.ListOrganizationAdminsRequest{
 				Id: organizationID,
-			}))
+			}, header)
+			if err != nil {
+				return err
+			}
+			res, err := client.ListOrganizationAdmins(cmd.Context(), req)
 			if err != nil {
@@ ... @@
 		},
 	}

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

Additionally, once admlistOrganizationCommand is refactored, the connect import on line 7 can be removed since no other function in this file will use it.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 55d41d00-ccdb-45bc-b0d2-95fc2a6f9e9a

📥 Commits

Reviewing files that changed from the base of the PR and between 789e0b7 and bdf9d10.

📒 Files selected for processing (8)
  • cmd/group.go
  • cmd/namespace.go
  • cmd/organization.go
  • cmd/permission.go
  • cmd/policy.go
  • cmd/project.go
  • cmd/role.go
  • cmd/user.go

@rohilsurana
Copy link
Member

@capable-average thanks for contributing. Could you have a look at one command that got missed, admlistOrganizationCommand, as highlighted by @CodeRabbit?

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)

cmd/organization.go (1)> 296-346: ⚠️ Potential issue | 🟡 Minor

Missing header flag in admlistOrganizationCommand.
This command still uses connect.NewRequest directly (line 317) and lacks the --header flag. Per the PR objective to "add --header flag to all CLI subcommands," this command should also be refactored to use the newRequest helper with header support.

🔧 Proposed fix to add header support

 func admlistOrganizationCommand(cliConfig *Config) *cli.Command {
+	var header string
 	cmd := &cli.Command{
 		Use:   "admlist",
 		Short: "list admins of an organization",
@@ ... @@
 			organizationID := args[0]
-			res, err := client.ListOrganizationAdmins(cmd.Context(), connect.NewRequest(&frontierv1beta1.ListOrganizationAdminsRequest{
+			req, err := newRequest(&frontierv1beta1.ListOrganizationAdminsRequest{
 				Id: organizationID,
-			}))
+			}, header)
+			if err != nil {
+				return err
+			}
+			res, err := client.ListOrganizationAdmins(cmd.Context(), req)
 			if err != nil {
@@ ... @@
 		},
 	}

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

Additionally, once admlistOrganizationCommand is refactored, the connect import on line 7 can be removed since no other function in this file will use it.

ℹ️ Review info

@coderabbitai
Copy link

coderabbitai bot commented Mar 11, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read the current state of cmd/organization.go around the admlistOrganizationCommand function
rg -n "admlistOrganizationCommand|connect\.NewRequest|ListOrganizationAdmins" cmd/organization.go -A3 -B3

Length of output: 705


@rohilsurana, confirmed — admlistOrganizationCommand in cmd/organization.go (line 317) still uses connect.NewRequest directly and is missing the --header / -H flag.

@capable-average, here is the complete fix needed for this function:

func admlistOrganizationCommand(cliConfig *Config) *cli.Command {
	var header string
	cmd := &cli.Command{
		Use:   "admlist",
		Short: "list admins of an organization",
		// ... existing fields ...
		RunE: func(cmd *cobra.Command, args []string) error {
			// ... existing client setup ...

			organizationID := args[0]
			req, err := newRequest(&frontierv1beta1.ListOrganizationAdminsRequest{
				Id: organizationID,
			}, header)
			if err != nil {
				return err
			}
			res, err := client.ListOrganizationAdmins(cmd.Context(), req)
			if err != nil {
				// ... existing error handling ...
			}
			// ... rest of existing code ...
		},
	}

	cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")

	return cmd
}

Additionally, once this is updated, the connectrpc.com/connect import at the top of cmd/organization.go can be removed since it will no longer be used anywhere in the file.

@capable-average
Copy link
Author

sure, can you also please confirm that '-H' being a required flag is intended?

@capable-average capable-average force-pushed the fix/add-header-flag-in-cli-subcommands branch from bdf9d10 to b80aee5 Compare March 11, 2026 14:31
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
cmd/user.go (1)

98-101: ⚠️ Potential issue | 🟡 Minor

Inconsistent: --header is required only in createUserCommand.

The --header flag is marked as required here (line 101) but is optional in editUserCommand, viewUserCommand, and listUserCommand. This inconsistency was also raised in the PR comments. If the header is meant to be optional across all commands (matching namespace.go), remove the MarkFlagRequired call.

Proposed fix to make header optional
 	cmd.Flags().StringVarP(&filePath, "file", "f", "", "Path to the user body file")
 	cmd.MarkFlagRequired("file")
 	cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
-	cmd.MarkFlagRequired("header")
cmd/role.go (1)

94-97: ⚠️ Potential issue | 🟡 Minor

Inconsistent: --header is required only in createRoleCommand.

Same issue as createUserCommand - the header flag is marked as required here but is optional in editRoleCommand, viewRoleCommand, and listRoleCommand. This creates an inconsistent user experience where only create operations mandate headers.

Proposed fix to make header optional
 	cmd.Flags().StringVarP(&filePath, "file", "f", "", "Path to the role body file")
 	cmd.MarkFlagRequired("file")
 	cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
-	cmd.MarkFlagRequired("header")

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 55a22f37-b3c5-4401-bb6c-cc37c85e4dc5

📥 Commits

Reviewing files that changed from the base of the PR and between bdf9d10 and b80aee5.

📒 Files selected for processing (8)
  • cmd/group.go
  • cmd/namespace.go
  • cmd/organization.go
  • cmd/permission.go
  • cmd/policy.go
  • cmd/project.go
  • cmd/role.go
  • cmd/user.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • cmd/permission.go
  • cmd/project.go
  • cmd/policy.go
  • cmd/group.go
  • cmd/organization.go

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cmd/organization.go (1)

96-97: ⚠️ Potential issue | 🟠 Major

Inconsistent: --header is required only for create, optional elsewhere.

The --header flag is marked as required here but is optional in edit, view, list, and admlist commands. The newRequest helper already handles empty headers gracefully by simply not setting any header. This was also raised in the PR comments.

Consider removing the required constraint for consistency:

Suggested fix
 	cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
-	cmd.MarkFlagRequired("header")

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9851f46e-67ff-4269-90c3-0995b8e8f4ee

📥 Commits

Reviewing files that changed from the base of the PR and between b80aee5 and ea928d4.

📒 Files selected for processing (1)
  • cmd/organization.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants