Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Accept custom command when launching shell#375

Merged
mangelajo merged 3 commits intomainfrom
shell-custom-command
Mar 26, 2025
Merged

Accept custom command when launching shell#375
mangelajo merged 3 commits intomainfrom
shell-custom-command

Conversation

@NickCao
Copy link
Copy Markdown
Collaborator

@NickCao NickCao commented Mar 24, 2025

Summary by CodeRabbit

  • New Features
    • The shell command now accepts a custom command as an optional argument, allowing users to input one or more commands at launch for enhanced flexibility.
    • Enhanced shell launching process with improved environment setup and command execution logic.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 24, 2025

Walkthrough

The pull request updates the shell command interface by introducing a new command parameter. The CLI function signature is updated to accept a tuple of strings, and this parameter is passed through to the launch_shell utility. The launch_shell function is modified to handle the optional command argument, altering the process setup before invoking a subprocess. These modifications standardize how custom commands are passed and executed in both the CLI and utility modules.

Changes

File(s) Change Summary
packages/jumpstarter-cli/jumpstarter_cli/shell.py Updated the shell function signature to include a command: tuple[str, ...] parameter; modified calls to launch_shell to supply the new parameter.
packages/jumpstarter/jumpstarter/common/utils.py Updated the launch_shell signature by adding an optional `command: tuple[str, ...]

Sequence Diagram(s)

sequenceDiagram
    participant User as CLI User
    participant Shell as Shell Handler
    participant Utils as Launch_Shell
    participant Subproc as Popen

    User->>Shell: Invoke shell with parameters (including command)
    Shell->>Utils: Call launch_shell(command=...)
    Utils->>Subproc: Execute Popen with command if provided
    Subproc-->>Utils: Return exit code
    Utils-->>Shell: Return exit code
    Shell-->>User: Relay exit code
Loading

Possibly Related PRs

Poem

I hopped through lines of code today,
Adding a command in a clever way.
Functions updated with a rhythmic beat,
Now shells launch commands, neat and sweet.
With a twitch of my whiskers, I celebrate this day!
🐇💻


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c8faec0 and 1bf9013.

📒 Files selected for processing (2)
  • packages/jumpstarter-cli/jumpstarter_cli/shell.py (2 hunks)
  • packages/jumpstarter/jumpstarter/common/utils.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/jumpstarter/jumpstarter/common/utils.py
🧰 Additional context used
🧬 Code Definitions (1)
packages/jumpstarter-cli/jumpstarter_cli/shell.py (1)
packages/jumpstarter/jumpstarter/common/utils.py (1)
  • launch_shell (83-116)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: Redirect rules - jumpstarter-docs
  • GitHub Check: Header rules - jumpstarter-docs
  • GitHub Check: Pages changed - jumpstarter-docs
  • GitHub Check: e2e
  • GitHub Check: pytest-matrix (3.11)
  • GitHub Check: pytest-matrix (3.13)
  • GitHub Check: pytest-matrix (3.12)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-utils Dockerfile.utils)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-devspace .devfile/Containerfile.client)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter Dockerfile)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-dev .devfile/Containerfile)
🔇 Additional comments (4)
packages/jumpstarter-cli/jumpstarter_cli/shell.py (4)

15-15: Add more detailed help text for the COMMAND argument.

While the docstring has been updated, it would be beneficial to enhance the command-line help text to clearly explain what the COMMAND argument does, its format, and provide examples for CLI users.

This matches the previous review comment from mangelajo, who suggested adding more command help. Consider adding content similar to what's in https://deploy-preview-375--jumpstarter-docs.netlify.app/head/cli/reference/jmp#cmdoption-jmp-shell-arg-COMMAND


23-23: LGTM! Good function signature and documentation.

The updated function signature correctly accepts the new command parameter as a tuple of strings, and the docstring is well-documented with a clear example showing how to use custom commands.

Also applies to: 25-33


43-49: LGTM! Correctly passes the command parameter.

The launch_shell call is properly updated to include the new command parameter, which aligns with the updated function signature in utils.py.


56-62: LGTM! Properly handles command in exporter config case.

The function correctly passes the command parameter to launch_shell when using ExporterConfigV1Alpha1, maintaining consistent behavior between different configuration types.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 24, 2025

Deploy Preview for jumpstarter-docs ready!

Name Link
🔨 Latest commit 62dae70
🔍 Latest deploy log https://app.netlify.com/sites/jumpstarter-docs/deploys/67e40b66461a5f000818a8f9
😎 Deploy Preview https://deploy-preview-375--jumpstarter-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Copy Markdown
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.

Actionable comments posted: 0

🧹 Nitpick comments (3)
packages/jumpstarter/jumpstarter/common/utils.py (2)

83-90: Function signature enhanced with optional command parameter

The updated launch_shell function signature now includes an optional keyword-only parameter command that accepts a tuple of strings or None. This allows for both interactive shell usage and execution of specific commands.

I notice the allow parameter type annotation changed from list[str] to [str]. This is unusual as [str] is not standard Python type annotation syntax - did you mean list[str]?

-def launch_shell(
-    host: str,
-    context: str,
-    allow: [str],
-    unsafe: bool,
-    *,
-    command: tuple[str, ...] | None,
-) -> int:
+def launch_shell(
+    host: str,
+    context: str,
+    allow: list[str],
+    unsafe: bool,
+    *,
+    command: tuple[str, ...] | None = None,
+) -> int:

98-98: Update function docstring to mention the command parameter

The docstring should be updated to include information about the new command parameter.

    Args:
        host: The jumpstarter host path
        context: The context of the shell ("local" or "remote")
        allow: List of allowed drivers
        unsafe: Whether to allow drivers outside of the allow list
+       command: Optional command to execute instead of launching an interactive shell
+
+    Returns:
+        The exit code of the launched shell process
packages/jumpstarter-cli/jumpstarter_cli/shell.py (1)

24-26: Update docstring to mention the command parameter

The function docstring should be updated to mention the new functionality of executing custom commands.

    """
    Spawns a shell connecting to a local or remote exporter
+
+    If a command is provided, it will be executed within the shell environment
+    instead of launching an interactive shell.
    """
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 892b71a and 7438907.

📒 Files selected for processing (2)
  • packages/jumpstarter-cli/jumpstarter_cli/shell.py (2 hunks)
  • packages/jumpstarter/jumpstarter/common/utils.py (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/jumpstarter-cli/jumpstarter_cli/shell.py (1)
packages/jumpstarter/jumpstarter/common/utils.py (1)
  • launch_shell (83-116)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: e2e
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-utils Dockerfile.utils)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-devspace .devfile/Containerfile.client)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter Dockerfile)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-dev .devfile/Containerfile)
🔇 Additional comments (6)
packages/jumpstarter/jumpstarter/common/utils.py (2)

99-104: Good refactoring: Environment setup separated from command execution

Clean refactoring that separates environment setup from command execution logic, making the code more modular and easier to maintain.


106-114: Well-implemented conditional command execution

The implementation correctly handles both cases - executing a specific command or launching the default shell. The code maintains the original behavior for interactive shells while adding support for custom command execution.

packages/jumpstarter-cli/jumpstarter_cli/shell.py (4)

15-15: Command argument added with variadic parameter support

Good implementation using nargs=-1 to allow capturing multiple command arguments. This allows users to pass multiple strings as a single command.


23-23: Type annotation added for command parameter

The function signature has been properly updated to include the new command parameter with appropriate type annotation.


35-41: Remote shell launch updated to support custom commands

The launch_shell call for remote shells has been properly updated to include the new command parameter.


48-54: Local shell launch updated to support custom commands

The launch_shell call for local shells has been properly updated to include the new command parameter.

@NickCao NickCao force-pushed the shell-custom-command branch from 7438907 to c8faec0 Compare March 24, 2025 18:15
Comment thread packages/jumpstarter-cli/jumpstarter_cli/shell.py
@NickCao NickCao force-pushed the shell-custom-command branch from c8faec0 to 1bf9013 Compare March 25, 2025 16:55
@mangelajo mangelajo enabled auto-merge March 26, 2025 14:12
@mangelajo mangelajo merged commit dbc50d2 into main Mar 26, 2025
18 checks passed
@NickCao NickCao deleted the shell-custom-command branch March 31, 2025 15:44
@mangelajo mangelajo added this to the 0.6.0 milestone May 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants