program .description(chalk.white('Clay allows you to instantly build and remix cloud hosted functions')) .version('0.5.2') .usage('<command>') .command('new [serviceName]') .description('creates a new service with the name [serviceName].') .action((cmd) => service.create(cmd, account))
.description(github.description()) .option( "-u, --username <username>",
program .description( `Create a root tree node with specified name. You can then complete other node fields using other DB admin tools.` ) .option("<nodeName>", "Root node name") .version(pkg.version) .action(async (nodeName) => { try { if (!process.argv.slice(2).length) { program.help(); } nodeName = nodeName.trim(); if (nodeName === "") throw new Error("Node Name can't be empty!"); const pool = getDBPool(); const queryer = new NestedSetModelQueryer(pool, "org_units"); const nodeId = await queryer.createRootNode({ name: nodeName }); console.log( chalk.green( `Root node with name: ${nodeName} created. \nId: ${nodeId}` ) ); } catch (e) { console.error(chalk.red(`Error: ${e}`)); } process.exit(0); }) .parse(process.argv);
program .description("List all resources") .version(pkg.version) .action(async () => { try { const result = await pool.query(`SELECT * FROM resources`); if (!result || !result.rows || !result.rows.length) { throw new Error("Cannot find any records!"); } const data = [["URI", "Name", "Description", "Operations"]]; for (let i = 0; i < result.rows.length; i++) { const res = result.rows[i]; res["operations"] = await getOperationsByResourceId(res["id"]); res["operations"] = res["operations"] .map((op) => op.uri) .join("\n"); delete res["id"]; data.push(Object.values(res)); } console.log(table(data)); } catch (e) { console.error(chalk.red(`Error: ${e}`)); } process.exit(0); }) .parse(process.argv);
program .description("calculate JWT token (only for testing purpose)") .option("<userId>", "User ID") .option( "[jwtSecret]", "Optional JWT secret. Default value: `" + DEFAULT_JWT_SECRET + "`" ) .version(pkg.version) .action(async (userId, jwtSecret) => { try { console.log(`JWT token for user ${userId} is: `); console.log( chalk.yellow( buildJwt( typeof jwtSecret === "string" ? jwtSecret : DEFAULT_JWT_SECRET, userId ) ) ); } catch (e) { console.error(chalk.red(`Error: ${e}`)); } process.exit(0); }) .parse(process.argv);
program .description("List all permissions") .version(pkg.version) .action(async () => {
program .description("assign the permission to a role") .option("<permissionId>", "Permission ID") .option("<roleId>", "Role ID")
program .description( "Delete the node specified and all its dependents from the tree." + "\nIf the node name is given instead of the node Id, the first located node (and its dependents) will be removed." +
program .description( "Move the node specified and all its dependents to the specified parent node." + "\nIf the node name is given instead of the node Id, the first located node (and its dependents) will be moved." +
program .description("Remove the specified user to from any org unit.") .option("<userNameOrId>", "user name or id") .version(pkg.version) .action(async (userNameOrId) => { try { if (process.argv.slice(2).length < 1) { program.help(); } userNameOrId = userNameOrId ? userNameOrId.trim() : ""; if (userNameOrId === "") throw new Error("User Name or Id can't be empty!"); const pool = getDBPool(); const userId = await getUserIdFromNameOrId(userNameOrId, pool); await pool.query( `UPDATE "users" SET "orgUnitId" = NULL WHERE "id" = $1`, [userId] ); console.log( chalk.green(`The user (id: ${userId}) has been unassigned.`) ); } catch (e) { console.error(chalk.red(`Error: ${e}`)); } process.exit(0); }) .parse(process.argv);
program .description( "Insert a node as a child node of the specified the parent node with specified name. " + "\nIf the parent node name is given instead of the parent node Id, the newly created child node will be inserted to the first located parent node."
program .description( "Assign the specified user to the nominated node." + "\nBoth `userNameOrId` & `nodeNameOrId` can be either entity name or Id. \n" +
program .description("assign the role to a user") .option("<roleId>", "Role ID") .option("<userId>", "User ID")
program .description("Remove a role from a user") .option("<roleId>", "Role ID") .option("<userId>", "User ID")
program .description("Remove a permission from a role") .option("<permissionId>", "Permission ID") .option("<roleId>", "Role ID")