Skip to content

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

Merged
lyrixx merged 1 commit intojolicode:mainfrom
Amoifr:feat-context-input-stdin
Mar 30, 2026
Merged

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

Conversation

@Amoifr
Copy link
Copy Markdown
Contributor

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

Comment thread doc/docs/getting-started/run.md
Comment thread examples/basic/run/run.php Outdated
@Amoifr Amoifr force-pushed the feat-context-input-stdin branch 3 times, most recently from b2671ff to eb71555 Compare March 27, 2026 11:09
@Amoifr
Copy link
Copy Markdown
Contributor 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!

@Amoifr Amoifr force-pushed the feat-context-input-stdin branch from eb71555 to fe538ff Compare March 30, 2026 07:29
Copy link
Copy Markdown
Member

@lyrixx lyrixx left a comment

Choose a reason for hiding this comment

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

Except one tiny comment, it's all good to me!

Thanks 👍🏼

Comment thread src/Context.php Outdated
This allows passing sensitive data (like passwords) to commands via stdin
instead of exposing them in command line arguments.

Closes jolicode#627
@lyrixx lyrixx force-pushed the feat-context-input-stdin branch from fe538ff to 05135d6 Compare March 30, 2026 14:24
@lyrixx lyrixx enabled auto-merge March 30, 2026 14:25
@lyrixx lyrixx merged commit ececd74 into jolicode:main Mar 30, 2026
12 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.

Allow setting Input in run()

3 participants