From 8648fc03e1a15d54d93759bff459db27753c0359 Mon Sep 17 00:00:00 2001 From: Daniel Bachler Date: Mon, 12 Aug 2024 22:35:09 +0200 Subject: [PATCH] Create a PR that changes the script in ./devTools/syncGraphersToR2 so 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). --- devTools/syncGraphersToR2/syncGraphersToR2.ts | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/devTools/syncGraphersToR2/syncGraphersToR2.ts b/devTools/syncGraphersToR2/syncGraphersToR2.ts index 44bf798ee54..a9ba14bfb98 100644 --- a/devTools/syncGraphersToR2/syncGraphersToR2.ts +++ b/devTools/syncGraphersToR2/syncGraphersToR2.ts @@ -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 @@ -273,13 +273,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) }