diff --git a/index.js b/index.js index 7eed525..86eb6cf 100755 --- a/index.js +++ b/index.js @@ -45,6 +45,7 @@ import { HAS_ASKED_OPT_IN_NAME } from "./scripts/analytics/config.js"; import { EVENT } from "./scripts/analytics/constants.js"; import { askOptIn } from "./scripts/analytics/scripts.js"; import { sentryMonitoring } from "./scripts/utils/sentry.js"; +import { setModuleDetails } from "./scripts/setModuleDetails.js"; const pkg = JSON.parse( fs.readFileSync(new URL("package.json", import.meta.url), "utf8") @@ -303,7 +304,11 @@ demo`; "--visibility": String, "--status": String, "--page": String, - "--unarchive": Boolean + "--unarchive": Boolean, + "--name": String, + "--description": String, + "--acceptance-criteria": String, + "--search-description": String }); let id; @@ -338,6 +343,24 @@ demo`; await modulesGet(id); break; + case "set": + id = args._[2]; + + if (!id) { + return invalid( + "Please provide the id of the module to change info for, i.e. modules set <123>" + ); + } + + await setModuleDetails(id, + args["--name"], + args["--description"], + args["--acceptance-criteria"], + args["--search-description"] + ); + + break; + case "archive": id = args._[2]; if (!id) { @@ -409,6 +432,9 @@ Commands available: demo Generate a local React Native and Django demo app add Install a module in the demo app remove Remove a module from the demo app + get Get information about a module by id + set Set information about a module by id such as name, description, acceptance criteria, and search description. The new values must be wrapped in quotes "". + create Create a new module of a given type create Create a new module of a given type commit Update an existing module from the demo source code init Initialize a blank modules repository @@ -447,6 +473,13 @@ Install one or modules to your demo app: Remove one or modules from your demo app: cb remove +Get information about a module by id: + cb modules get + +Set information about a module by id such as name, description, acceptance criteria, and search description: + cb modules set --name "" --description "" --acceptance-criteria "" --search-description "" + The new values must be wrapped in quotes "". + Install modules from other directory: cb add --source ../other-repository diff --git a/scripts/setModuleDetails.js b/scripts/setModuleDetails.js new file mode 100644 index 0000000..0355242 --- /dev/null +++ b/scripts/setModuleDetails.js @@ -0,0 +1,42 @@ +import ora from "ora"; +import { invalid, valid } from "../utils.js"; +import { apiClient } from "./utils/apiClient.js"; + +export const setModuleDetails = async ( + id, name, description, searchDescription, acceptanceCriteria +) => { + const patchBody = {}; + + if (name) { + patchBody.title = name; + } + if (description) { + patchBody.description = description; + } + if (searchDescription) { + patchBody.search_description = searchDescription; + } + if (acceptanceCriteria) { + patchBody.acceptance_criteria = acceptanceCriteria; + } + if (Object.keys(patchBody).length === 0) { + invalid("No module details were provided for the update. To correctly save the new value, please enclose it in double quotes. For example, use --description \"Your detailed description here\"."); + return; + } + const patchSpinner = ora( + "Updating module details." + ).start(); + + const patchResponse = await apiClient.patch({ + path: `/v1/catalog/module/${id}`, + body: patchBody + }).then(patchSpinner.stop()); + + if (patchResponse.ok) { + valid(`Module details updated for ${id}.`); + } else if (patchResponse.status === 404) { + invalid(`Cannot find requested module with id ${id}.`); + } else { + invalid("Unable to update modules details. Please try again later."); + } +};