feat: add features to stdin commands#5981
Open
qwertycxz wants to merge 5 commits into
Open
Conversation
1. Add support for input commands in `pm2 logs` 2. Add support for using names in `pm2 attach` and `pm2 send` 3. Update documentation for new features
Author
|
I made a demo for this |
There was a problem hiding this comment.
Pull request overview
This PR extends PM2’s stdin interaction features by allowing pm2 attach / pm2 send to target processes by name as well as id, and by adding an interactive stdin “command mode” to pm2 logs via --attach-input.
Changes:
- Add
Client.getUniqueProcessIdByName()and use it to support<id|name>inpm2 attachandpm2 send. - Add
pm2 logs --attach-inputto read stdin lines in the form<id|name> [line] ...and forward them to the targeted process stdin. - Update example documentation for the new logs stdin interaction flow.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
types/index.d.ts |
Adds new type declarations for stdin/attach APIs (currently duplicates existing declarations). |
lib/Client.js |
Introduces getUniqueProcessIdByName() helper used for name-based targeting. |
lib/binaries/CLI.js |
Updates CLI commands to accept `<id |
lib/API/Extra.js |
Implements name resolution in sendLineToStdin/attach and adds attachInput(). |
examples/interact-via-stdin/README.md |
Documents the new pm2 logs --attach-input workflow. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| }; | ||
|
|
||
| /** | ||
| * Get process id by name and check if only one process is hitted |
Comment on lines
+709
to
+716
| * @param {string} name Name of the process to search for | ||
| * @param {(err: string, id: string) => void} cb Callback function to handle the result | ||
| */ | ||
| Client.prototype.getUniqueProcessIdByName = function(name, cb) { | ||
| this.getProcessIdByName(name, function(err, list) { | ||
| if (err) return cb(err); | ||
| if (list.length === 1) return cb(null, list[0]); | ||
| cb(`Expected exactly one process with name "${name}", but found ${list.length}.`); |
Comment on lines
687
to
688
| .action(function(pm_id, separator) { | ||
| pm2.attach(pm_id, separator); |
Comment on lines
927
to
+938
| if (cmd.nostream === true) | ||
| pm2.printLogs(id, line, raw, timestamp, exclusive); | ||
| else if (cmd.json === true) | ||
| Logs.jsonStream(pm2.Client, id); | ||
| else if (cmd.format === true) | ||
| Logs.formatStream(pm2.Client, id, false, 'YYYY-MM-DD-HH:mm:ssZZ', exclusive, highlight); | ||
| else | ||
| pm2.streamLogs(id, line, raw, timestamp, exclusive, highlight); | ||
|
|
||
| if (cmd.attachInput) { | ||
| pm2.attachInput(); | ||
| } |
Comment on lines
+806
to
+813
| rl.on('line', function(input) { | ||
| var line = input.split(' '); | ||
| that.sendLineToStdin(line.shift(), line.join(' '), function(err) { | ||
| if (err) { | ||
| that.exitCli(); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pm2 logspm2 attachandpm2 sendUsage