Skip to content

feat(cmd): add --runtime flag to init command#73

Merged
feloy merged 1 commit intokortex-hub:mainfrom
feloy:flag-runtime
Mar 16, 2026
Merged

feat(cmd): add --runtime flag to init command#73
feloy merged 1 commit intokortex-hub:mainfrom
feloy:flag-runtime

Conversation

@feloy
Copy link
Contributor

@feloy feloy commented Mar 16, 2026

Add mandatory --runtime flag to the init command for selecting the runtime implementation when registering workspaces. The runtime can be specified via:

  • --runtime/-r flag (highest priority)
  • KORTEX_CLI_DEFAULT_RUNTIME environment variable
  • Error if neither is set (runtime is required)

Updated README.md with comprehensive Environment Variables section documenting KORTEX_CLI_DEFAULT_RUNTIME and KORTEX_CLI_STORAGE, including usage examples and priority order.

Resolves #51

@coderabbitai
Copy link

coderabbitai bot commented Mar 16, 2026

Warning

Rate limit exceeded

@feloy has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 26 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0ba6d44f-e74b-43f0-9908-590f07a8d91d

📥 Commits

Reviewing files that changed from the base of the PR and between 06627ea and b751558.

📒 Files selected for processing (3)
  • README.md
  • pkg/cmd/init.go
  • pkg/cmd/init_test.go
📝 Walkthrough

Walkthrough

This PR introduces a --runtime flag and KORTEX_CLI_DEFAULT_RUNTIME environment variable to the init command, allowing users to specify the runtime implementation. The runtime can be provided via flag (highest priority), environment variable, or defaults to an error if neither is set. Documentation and tests are updated accordingly.

Changes

Cohort / File(s) Summary
Documentation
README.md
Added Environment Variables section documenting KORTEX_CLI_DEFAULT_RUNTIME and KORTEX_CLI_STORAGE with usage, priority, and examples. Updated command examples to explicitly show --runtime flag usage and reflect new runtime/storage configuration approach.
Init Command Implementation
pkg/cmd/init.go
Added runtime field to initCmd struct and new --runtime (-r) flag. Introduced preRun logic to resolve runtime from flag, environment variable, or error if neither provided. Replaced hard-coded "fake" runtime with resolved i.runtime value.
Init Command Tests
pkg/cmd/init_test.go
Updated all test cases to initialize runtime field in initCmd. Added test cases for runtime resolution logic (flag precedence, environment variable fallback, missing runtime error). Updated E2E test invocations to include --runtime fake flag across workspace registration and output scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • feat: init command #23: Introduced the initCmd struct that this PR extends with runtime field, flag, and resolution logic.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the implementation of the --runtime flag, priority order, environment variable support, and README updates, all relevant to the changeset.
Linked Issues check ✅ Passed The PR successfully implements all requirements from issue #51: adds --runtime flag, supports KORTEX_CLI_DEFAULT_RUNTIME environment variable, enforces flag precedence, and requires runtime specification.
Out of Scope Changes check ✅ Passed All changes are directly related to issue #51: init.go implements the flag logic, init_test.go adds corresponding tests, and README.md documents the new feature.
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding a --runtime flag to the init command, which is the primary focus of the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 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 use your project's `golangci-lint` configuration to improve the quality of Go code reviews.

Add a configuration file to your project to customize how CodeRabbit runs golangci-lint.

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.

🧹 Nitpick comments (2)
pkg/cmd/init.go (1)

147-151: Runtime validation relies on downstream manager.

The runtime value is passed directly to manager.Add() without pre-validation. This is acceptable since manager.Add() calls m.runtimeRegistry.Get(runtimeType) (per the context snippet from pkg/instances/manager.go:162) which will return an error if the runtime is invalid. However, consider whether early validation would provide a clearer error message to users.

💡 Optional: Add early runtime validation for clearer error messages

You could validate the runtime earlier in preRun to provide a more user-friendly error:

// After determining runtime, validate it exists
if _, err := manager.GetRuntime(i.runtime); err != nil {
    return outputErrorIfJSON(cmd, i.output, fmt.Errorf("invalid runtime %q: %w", i.runtime, err))
}

This would require exposing a method to check runtime validity, but could improve the user experience with error messages like invalid runtime "typo": runtime not found instead of the current failed to get runtime: ... message.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/cmd/init.go` around lines 147 - 151, The runtime is passed straight into
i.manager.Add without early validation; add an early check (e.g., in preRun
after resolving i.runtime) that verifies the runtime exists via the manager
runtime lookup before calling i.manager.Add to yield a clearer error.
Specifically, call the runtime validation method on the manager (e.g.,
manager.GetRuntime or a GetRuntime-like API) using i.runtime and return
outputErrorIfJSON(cmd, i.output, fmt.Errorf("invalid runtime %q: %w", i.runtime,
err)) on error so Add only runs for known runtimes; update preRun to perform
this validation before proceeding to i.manager.Add.
pkg/cmd/init_test.go (1)

468-522: Environment variable tests correctly avoid parallel execution.

The tests using t.Setenv() correctly avoid calling t.Parallel() as per the coding guideline. The nested subtest structure is appropriate for organizing related test cases.

However, consider simplifying the nested structure. The outer t.Run at line 468 creates a scope that only contains one inner t.Run, which adds unnecessary nesting.

💡 Optional: Flatten unnecessary nested test structure
-	t.Run("uses environment variable when runtime flag is not provided", func(t *testing.T) {
-		// Note: Cannot use t.Parallel() when using t.Setenv()
-
-		t.Run("with valid runtime from env", func(t *testing.T) {
-			t.Setenv("KORTEX_CLI_DEFAULT_RUNTIME", "fake")
+	t.Run("uses environment variable when runtime flag is not provided", func(t *testing.T) {
+		// Note: Cannot use t.Parallel() when using t.Setenv()
+		t.Setenv("KORTEX_CLI_DEFAULT_RUNTIME", "fake")
 
-			tempDir := t.TempDir()
+		tempDir := t.TempDir()
 			// ... rest of test
-		})
 	})
 
-	t.Run("runtime flag takes precedence over environment variable", func(t *testing.T) {
-		// Note: Cannot use t.Parallel() when using t.Setenv()
-
-		t.Run("flag overrides env", func(t *testing.T) {
-			t.Setenv("KORTEX_CLI_DEFAULT_RUNTIME", "env-runtime")
+	t.Run("runtime flag takes precedence over environment variable", func(t *testing.T) {
+		// Note: Cannot use t.Parallel() when using t.Setenv()
+		t.Setenv("KORTEX_CLI_DEFAULT_RUNTIME", "env-runtime")
 
-			tempDir := t.TempDir()
+		tempDir := t.TempDir()
 			// ... rest of test
-		})
 	})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/cmd/init_test.go` around lines 468 - 522, The outer wrapper t.Run that
only contains a single nested t.Run is unnecessary; simplify the tests by
removing the redundant outer t.Run and promote the inner subtests (e.g., "with
valid runtime from env" and "flag overrides env") to top-level subtests so each
directly calls t.Setenv, creates initCmd{runtime: ...}, constructs the
cobra.Command with the same flags and tempDir, and invokes c.preRun; keep the
existing assertions that c.runtime equals the expected value and retain the
comment about not using t.Parallel() when using t.Setenv(); references: tests
exercising initCmd.preRun and the subtest names "with valid runtime from env"
and "flag overrides env".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pkg/cmd/init_test.go`:
- Around line 468-522: The outer wrapper t.Run that only contains a single
nested t.Run is unnecessary; simplify the tests by removing the redundant outer
t.Run and promote the inner subtests (e.g., "with valid runtime from env" and
"flag overrides env") to top-level subtests so each directly calls t.Setenv,
creates initCmd{runtime: ...}, constructs the cobra.Command with the same flags
and tempDir, and invokes c.preRun; keep the existing assertions that c.runtime
equals the expected value and retain the comment about not using t.Parallel()
when using t.Setenv(); references: tests exercising initCmd.preRun and the
subtest names "with valid runtime from env" and "flag overrides env".

In `@pkg/cmd/init.go`:
- Around line 147-151: The runtime is passed straight into i.manager.Add without
early validation; add an early check (e.g., in preRun after resolving i.runtime)
that verifies the runtime exists via the manager runtime lookup before calling
i.manager.Add to yield a clearer error. Specifically, call the runtime
validation method on the manager (e.g., manager.GetRuntime or a GetRuntime-like
API) using i.runtime and return outputErrorIfJSON(cmd, i.output,
fmt.Errorf("invalid runtime %q: %w", i.runtime, err)) on error so Add only runs
for known runtimes; update preRun to perform this validation before proceeding
to i.manager.Add.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8d8c7556-0ad8-4a6e-be2b-2768390d4947

📥 Commits

Reviewing files that changed from the base of the PR and between 2f5c00b and 06627ea.

📒 Files selected for processing (3)
  • README.md
  • pkg/cmd/init.go
  • pkg/cmd/init_test.go

@feloy feloy changed the title feat(cmd): add --runtime flag to init command feat(cmd): add --runtime flag to init command Mar 16, 2026
@feloy feloy requested review from benoitf and jeffmaury March 16, 2026 13:25
Add mandatory --runtime flag to the init command for selecting the runtime
implementation when registering workspaces. The runtime can be specified via:
- --runtime/-r flag (highest priority)
- KORTEX_CLI_DEFAULT_RUNTIME environment variable
- Error if neither is set (runtime is required)

Updated README.md with comprehensive Environment Variables section
documenting KORTEX_CLI_DEFAULT_RUNTIME and KORTEX_CLI_STORAGE, including
usage examples and priority order.

Resolves kortex-hub#51

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Philippe Martin <phmartin@redhat.com>
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@feloy feloy merged commit 29bd323 into kortex-hub:main Mar 16, 2026
6 checks passed
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.

add a --runtime flag to init

3 participants