Fix flow errors in fetchAndPrintGithubRepo.js (#240)

Fixing the flow error corresponded to (correctly) documenting that the
GitHub token is mandatory, not optional.

Test plan: `yarn travis --full` still passes.
This commit is contained in:
Dandelion Mané 2018-05-08 14:24:11 -07:00 committed by GitHub
parent d34503799c
commit 1647c1abac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,4 @@
// @no-flow // @flow
/* /*
* Command-line utility to fetch GitHub data using the API in * Command-line utility to fetch GitHub data using the API in
* ../fetchGithubRepo, and print it to stdout. Useful for testing or * ../fetchGithubRepo, and print it to stdout. Useful for testing or
@ -19,16 +19,14 @@ function parseArgs() {
const argv = process.argv.slice(2); const argv = process.argv.slice(2);
const fail = () => { const fail = () => {
const invocation = process.argv.slice(0, 2).join(" "); const invocation = process.argv.slice(0, 2).join(" ");
throw new Error(`Usage: ${invocation} REPO_OWNER REPO_NAME [TOKEN]`); throw new Error(`Usage: ${invocation} REPO_OWNER REPO_NAME GITHUB_TOKEN`);
}; };
if (argv.length < 2) { if (argv.length < 2) {
fail(); fail();
} }
const [repoOwner, repoName, ...rest] = argv; const [repoOwner, repoName, githubToken, ...rest] = argv;
const result = {repoOwner, repoName}; const result = {repoOwner, repoName, githubToken};
if (rest.length === 1) { if (rest.length > 0) {
result.token = rest[0];
} else if (rest.length > 1) {
fail(); fail();
} }
return result; return result;
@ -36,7 +34,7 @@ function parseArgs() {
function main() { function main() {
const args = parseArgs(); const args = parseArgs();
fetchGithubRepo(args.repoOwner, args.repoName, args.token) fetchGithubRepo(args.repoOwner, args.repoName, args.githubToken)
.then((data) => { .then((data) => {
console.log(stringify(data, {space: 4})); console.log(stringify(data, {space: 4}));
}) })