-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: export
@octoherd/cli/run
(#16)
- Loading branch information
Showing
7 changed files
with
125 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export const cliOptions = { | ||
"octoherd-token": { | ||
description: | ||
'Requires the "public_repo" scope for public repositories, "repo" scope for private repositories.', | ||
demandOption: true, | ||
type: "string", | ||
}, | ||
"octoherd-cache": { | ||
description: | ||
"Cache responses for debugging. Creates a ./cache folder if flag is set. Override by passing custom path", | ||
type: "string", | ||
}, | ||
"octoherd-debug": { | ||
description: "Show debug logs", | ||
type: "boolean", | ||
default: false, | ||
}, | ||
"octoherd-bypass-confirms": { | ||
description: "Bypass prompts to confirm mutating requests", | ||
type: "boolean", | ||
default: false, | ||
}, | ||
}; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import yargs from "yargs"; | ||
import { VERSION as OctokitVersion } from "@octoherd/octokit"; | ||
import chalk from "chalk"; | ||
|
||
import { octoherd } from "../index.js"; | ||
import { VERSION } from "../version.js"; | ||
import { cliOptions } from "./cli-options.js"; | ||
|
||
/** | ||
* Function is used by Octoherd Script modules to provide a dedicated CLI binary | ||
* | ||
* import { script } from "./script.js"; | ||
* import { run } from "@octoherd/cli/run"; | ||
* run(script); | ||
* | ||
* @param {function} script Octoherd Script function | ||
*/ | ||
export function run(script) { | ||
const argv = yargs | ||
.usage("Usage: $0 [options] [repos...]") | ||
.example( | ||
"$0 --token 0123456789012345678901234567890123456789 octokit/rest.js" | ||
) | ||
.command("$0 [repos...]", "", (yargs) => { | ||
yargs.positional("repos", { | ||
demandOption: true, | ||
describe: | ||
"One or multiple arrays in the form of 'repo-owner/repo-name'. 'repo-owner/*' will find all repositories for one owner. '*' will find all repositories the user has access to", | ||
default: [], | ||
}); | ||
}) | ||
.options(cliOptions) | ||
.version(VERSION) | ||
.epilog(`copyright 2020-${new Date().getFullYear()}`).argv; | ||
|
||
const { _, $0, repos, ...options } = argv; | ||
|
||
console.log( | ||
`\n${chalk.bold("Running @octoherd/cli v%s")} ${chalk.gray( | ||
"(@octoherd/octokit v%s, Node.js: %s, %s %s)" | ||
)}\n`, | ||
VERSION, | ||
OctokitVersion, | ||
process.version, | ||
process.platform, | ||
process.arch | ||
); | ||
|
||
octoherd({ ...options, octoherdScript: script, octoherdRepos: repos }).catch( | ||
(error) => { | ||
console.error(error); | ||
process.exit(1); | ||
} | ||
); | ||
} | ||
|
||
import { script } from "../../script-star-or-unstar/script.js"; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { components } from "@octokit/openapi-types"; | ||
|
||
export { Octokit } from "@octoherd/octokit"; | ||
export type Repository = components["schemas"]["repository"]; |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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