Skip to content

Add input option to Context for passing data to process stdin#799

Open
Amoifr wants to merge 1 commit intojolicode:mainfrom
Amoifr:feat-context-input-stdin
Open

Add input option to Context for passing data to process stdin#799
Amoifr wants to merge 1 commit intojolicode:mainfrom
Amoifr:feat-context-input-stdin

Conversation

@Amoifr
Copy link
Copy Markdown

@Amoifr Amoifr commented Mar 27, 2026

Closes #627

Description

This PR adds an input option to the Context class, allowing users to pass data to a process via stdin. This is useful for commands that require sensitive input (like passwords) without exposing them in command line arguments.

Usage

use function Castor\context;
use function Castor\run;

// Pass sensitive data via stdin instead of command arguments
run(
    ['zip', '-e', 'archive.zip', 'files/'],
    context: context()->withInput("mypassword\nmypassword\n"),
);

Changes

  • Add input property to Context class
  • Add withInput() method to Context class
  • Update ProcessRunner::run() to use the input when provided
  • Add example and documentation

Copy link
Copy Markdown
Member

@pyrech pyrech left a comment

Choose a reason for hiding this comment

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

Hi @Amoifr, thanks for your PR 🎉

At first sight, it looks good. I just left two comments around doc/example. Could you also add a test for this feature by running bin/generate-tests.php ?

Thanks again ✨

@Amoifr Amoifr force-pushed the feat-context-input-stdin branch 2 times, most recently from d432275 to b2671ff Compare March 27, 2026 11:08
This allows passing sensitive data (like passwords) to commands via stdin
instead of exposing them in command line arguments.

Closes jolicode#627
@Amoifr Amoifr force-pushed the feat-context-input-stdin branch from b2671ff to eb71555 Compare March 27, 2026 11:09
@Amoifr
Copy link
Copy Markdown
Author

Amoifr commented Mar 27, 2026

Thanks for the review @pyrech! 🙏

I've pushed a fix:

  • Moved the example to its own file (examples/basic/run/input.php)
  • Updated the doc to use {% include %}
  • Generated the tests with bin/generate-tests.php

Let me know if this looks better!

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.

Allow setting Input in run()

2 participants