Skip to content

Commit

Permalink
Create a PR that changes the script in ./devTools/syncGraphersToR2 so…
Browse files Browse the repository at this point in the history
… that it supports multiple commands

Add support for multiple commands in `syncGraphersToR2.ts` script.

* **Refactor existing implementation:**
  - Move the existing implementation to the "sync" subcommand.
  - Update the `main` function to handle the new subcommand structure.
  - Parse the command-line arguments to determine which subcommand to execute.

* **Add new subcommand:**
  - Add a new "store-dev-by-slug" subcommand with a dummy implementation.
  - Add a help message for the new subcommand.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/owid/owid-grapher?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
danyx23 committed Aug 13, 2024
1 parent 87f0855 commit ed7d910
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions devTools/syncGraphersToR2/syncGraphersToR2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ async function syncWithR2(
}
}

async function main(parsedArgs: parseArgs.ParsedArgs, dryRun: boolean) {
async function sync(parsedArgs: parseArgs.ParsedArgs, dryRun: boolean) {
if (
GRAPHER_CONFIG_R2_BUCKET === undefined ||
GRAPHER_CONFIG_R2_BUCKET_PATH === undefined
Expand Down Expand Up @@ -276,13 +276,41 @@ async function main(parsedArgs: parseArgs.ParsedArgs, dryRun: boolean) {
})
}

async function storeDevBySlug(parsedArgs: parseArgs.ParsedArgs, dryRun: boolean) {
console.log("Dummy implementation for store-dev-by-slug")
}

async function main(parsedArgs: parseArgs.ParsedArgs) {
const dryRun = parsedArgs["dry-run"]

const command = parsedArgs._[0]

switch (command) {
case "sync":
await sync(parsedArgs, dryRun)
break
case "store-dev-by-slug":
await storeDevBySlug(parsedArgs, dryRun)
break
default:
console.log(
`Unknown command: ${command}\n\nAvailable commands:\n sync\n store-dev-by-slug`
)
break
}
}

const parsedArgs = parseArgs(process.argv.slice(2))
if (parsedArgs["h"]) {
console.log(
`syncGraphersToR2.js - sync grapher configs from the chart_configs table to R2
--dry-run: Don't make any actual changes to R2`
--dry-run: Don't make any actual changes to R2
Commands:
sync: Sync grapher configs to R2
store-dev-by-slug: Dummy implementation for store-dev-by-slug`
)
} else {
main(parsedArgs, parsedArgs["dry-run"])
main(parsedArgs)
}

0 comments on commit ed7d910

Please sign in to comment.