-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for piped input #66
base: main
Are you sure you want to change the base?
Conversation
@@ -108,7 +108,7 @@ export async function octoherd(options) { | |||
octokit, | |||
script: octoherdScript, | |||
userOptions, | |||
octoherdReposPassedAsFlag: !!octoherdRepos, | |||
octoherdReposPassedAsFlag: octoherdRepos.length, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the change made in https://github.com/octoherd/cli/pull/66/files#diff-3d406faa7d382dc8468988af3792bf78dfd057c449283aae37ad03a68d6b5142R27 octoherdRepos
will be at least an empty array
@@ -20,6 +22,10 @@ const argv = await yargs(hideBin(process.argv)) | |||
.version(VERSION) | |||
.epilog(EPILOG).argv; | |||
|
|||
const stdin = await getStdin(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get-stdin is responsible to get the piped input and returns a string
Just a quick update. I made some progress (at least I understand the problem) a little better. However piping is a little more complicated than I expected. The problemLet's start simple with the following import enquirer from 'enquirer';
const prompt = new enquirer.Select({
name: 'color',
message: 'Pick a flavor',
choices: ['apple', 'grape', 'watermelon', 'cherry', 'orange'],
});
prompt
.run()
.then((answer) => console.log('Answer:', answer))
.catch(console.error); When running Now if we pipe some random value Researchipt (Interactive Pipe To) is a cli written in Node.js and the piping works as expected. The project is using inquirer, and first I though import { promisify } from "util";
import enquirer from "enquirer";
import reopenTTY from 'reopen-tty';
function end() {
process.exit(0);
}
function error(err) {
console.error(err);
process.exit(1);
}
Promise.all([promisify(reopenTTY.stdin)(), promisify(reopenTTY.stdout)()]).then(
(stdio) => {
const [ttyStdin, ttyStdout] = stdio;
const stdin = ttyStdin;
const stdout = ttyStdout;
const prompt = new enquirer.Select({
name: 'color',
message: 'Pick a flavor',
choices: ['apple', 'grape', 'watermelon', 'cherry', 'orange'],
stdout,
stdin,
});
prompt
.run()
.then((answer) => console.log('Answer:', answer))
.then(end)
.catch(error);
}
); Disclaimer, I'm new to this as well and this comment describes my current understanding (which might be wrong or partial incomplete). From the TTY documentation page
When piping something to a Node.js process, This is how I understood how it after reading and try and error the code snippet. How to integrate this into Octoherd is something for later this week. |
Thanks for doing all the research, this is great! Maybe we could detect piping mode, and in that case require all arguments to be set by CLI flags? And if one is missing, throw an error. That way we would never get into an interactive mode. I think we also thought about adding an explicit flag to prevent interactive mode, which is useful e.g. scripts run in CI, so we would need to create that anyway. If it would help, maybe we do that first, as a preparation for piping support, as it seems to unblock it? What do you think @stefanbuck @oscard0m |
From my understanding we can use
So in comparison to |
only if a required argument was not set. The new flag would set |
@stefanbuck be careful with publishing a screenshot with your GitHub Token. Make sure you expire/delete it and create a new one.
I don't have a deep experience with CLI's in Node.js and
Is not
I think this is the user's responsibility. When piping something as input for the command, it should be read, but still, be in
For CI environments I come up with the following utility library. I think we should open a different discussion for |
Resolves #65
To make it easier to operate on hundreds of repositories, this pull request allows you to pipe input to
octoherd
.Example
list.txt
When piping a list of repositories, lines starting with a comment delimiter such as
#
or//
will be ignored.