Skip to content

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

Open
capable-average wants to merge 3 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 3 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
Contributor

coderabbitai bot commented Mar 10, 2026

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added a --header / -H flag to create, edit, view, and list commands across groups, namespaces, organizations (create now requires a header), permissions, policies, projects, roles, and users; header values are propagated with requests.
  • Tests

    • Updated test expectations to include the header flag in required-flag error messages.
  • Chores

    • Made the seed command's header flag required.

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 and updates tests to expect the additional required header flag where applicable.

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.
Tests — expected flag errors updated
cmd/group_test.go, cmd/organization_test.go, cmd/permission_test.go, cmd/policy_test.go, cmd/project_test.go, cmd/role_test.go
Updated expected error strings to include the newly required header flag (e.g., required flag(s) "file", "header" not set).
Seed command flag validation
cmd/seed.go
Marked the header flag as required for the seed command via cmd.MarkFlagRequired("header").

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • rohilsurana
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

CodeRabbit can approve the review once all CodeRabbit's comments are resolved.

Enable the reviews.request_changes_workflow setting to automatically approve the review once all CodeRabbit's comments are resolved.

@capable-average
Copy link
Author

closes #1392

Copy link
Contributor

@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
Contributor

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
Contributor

@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
Contributor

@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

@whoAbhishekSah
Copy link
Member

@capable-average Yes, the --header / -H flag is needed across all subcommands. The way it works: connect.NewRequest creates a bare request with no headers, while newRequest (in cmd/context.go) wraps it and attaches the header value from the -H flag. So all call sites should use newRequest to make the flag actually work.

@capable-average capable-average force-pushed the fix/add-header-flag-in-cli-subcommands branch from ea928d4 to e30d271 Compare March 18, 2026 16:17
Copy link
Contributor

@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.

🧹 Nitpick comments (3)
cmd/seed.go (1)

56-65: Conflicting flag logic: --header is marked required but fallback logic for missing header remains.

Line 92 marks --header as required with cmd.MarkFlagRequired("header"), yet lines 56-65 contain a fallback path that loads the header from config when it's empty. With the required flag enforcement, this fallback code and the --config flag (line 93) become unreachable in normal CLI flow. Remove the fallback logic and config flag if --header should always be required, or remove the MarkFlagRequired() call if the fallback behavior is intentional.

cmd/organization.go (1)

231-232: Consider whether --header should be required for read-only commands.

Making --header required for view and list commands may degrade CLI usability since users must always provide a header even for simple read operations. If the header is only needed occasionally (e.g., for authentication), consider making it optional for these commands.

This applies similarly to listOrganizationCommand (lines 292-293) and admlistOrganizationCommand (lines 352-353).

cmd/project.go (1)

231-232: Same UX consideration as organization commands.

As noted in cmd/organization.go, making --header required for read-only view and list commands may impact usability. This applies to lines 231-232 and 295-296.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 23f9b34a-b5eb-4a93-a454-6b217565b193

📥 Commits

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

📒 Files selected for processing (15)
  • cmd/group.go
  • cmd/group_test.go
  • cmd/namespace.go
  • cmd/organization.go
  • cmd/organization_test.go
  • cmd/permission.go
  • cmd/permission_test.go
  • cmd/policy.go
  • cmd/policy_test.go
  • cmd/project.go
  • cmd/project_test.go
  • cmd/role.go
  • cmd/role_test.go
  • cmd/seed.go
  • cmd/user.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • cmd/namespace.go
  • cmd/role.go
  • cmd/user.go
  • cmd/permission.go
  • cmd/policy.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.

3 participants