Commit f8c29e3

Anton Golub <antongolub@antongolub.com>
2023-10-09 20:15:30
feat: provide symmetrical config via cli and env
1 parent 1d949d7
Changed files (2)
src/main.ts
@@ -13,17 +13,17 @@ import { updateBadges } from './update-badges.js'
 
 void (async function main() {
   const argv = minimist(process.argv.slice(2), {
-    string: ['data', 'repo'],
+    string: ['data', 'repo', 'token'],
   })
-  const [username] = argv._
-  const [owner, repo]: [string | undefined, string | undefined] = argv.repo
-    ? argv.repo.split('/', 2)
-    : [undefined, undefined]
+  const {GITHUB_TOKEN, GITHUB_USER, GITHUB_REPO} = process.env
+  const [username = GITHUB_USER] = argv._
+  const [owner, repo]: [string?, string?] = (argv.repo || GITHUB_REPO)?.split('/', 2) || []
   const dataPath: string = argv.data ?? ''
+  const token = argv.token || GITHUB_TOKEN
 
   const MyOctokit = Octokit.plugin(retry, throttling)
   const octokit = new MyOctokit({
-    auth: process.env.GITHUB_TOKEN,
+    auth: token,
     log: console,
     throttle: {
       onRateLimit: (retryAfter, options: any, octokit, retryCount) => {
.gitignore
@@ -1,3 +1,4 @@
 /node_modules/
 /data/
 /dist/
+yarn.lock