-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const commentsDelimiter = ['//', '#']; | ||
|
||
export function parseInput(content = '') { | ||
return content | ||
.split('\n') | ||
.map(line => line.trim()) | ||
.filter(Boolean) // Ignore empty lines | ||
.filter(line => { | ||
// Ignore lines starting with a comment delimiter | ||
if (commentsDelimiter.some(block => line.startsWith(block))) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 |
||
}; | ||
|
||
await runScriptAgainstRepositories(state, octoherdRepos); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { parseInput } from "../bin/parse-input.js"; | ||
import { suite } from "uvu"; | ||
import { equal } from "uvu/assert"; | ||
|
||
const parseTest = suite("parse-input"); | ||
|
||
parseTest("when input is empty", () => { | ||
equal([], parseInput()); | ||
}); | ||
|
||
parseTest("when input is a single line", () => { | ||
equal(['foo'], parseInput('foo')); | ||
}); | ||
|
||
parseTest("when input has multipe lines", () => { | ||
equal(['foo', 'bar'], parseInput('foo\nbar')); | ||
}); | ||
|
||
parseTest("when input contains multipe empty lines", () => { | ||
equal(['foo', 'bar', 'baz'], parseInput('foo\n\n\nbar\n\nbaz\n\n')); | ||
}); | ||
|
||
parseTest("when line contains leading or trailing whitespaces", () => { | ||
equal(['foo', 'bar'], parseInput('foo \n bar')); | ||
}); | ||
|
||
parseTest("when lines start with a comment delimiter", () => { | ||
equal(['foo'], parseInput('foo\n//bar\n#baz')); | ||
}); | ||
|
||
parseTest.run(); |
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