runUser
uses tcmts.cli.main.execute, which uses tcmts.cli.help.usageError, which uses tcmts.cli.help.usageOf, which uses tcmts.cli.style.bold, which uses node:util
Runs tcm user.
import { routeUser } from "#codebase/tcmts/cli/commands"; import { execute } from "#codebase/tcmts/cli/main"; import type { Context } from "#codebase/tcmts/cli/run"; import { bold, dim, green } from "#codebase/tcmts/cli/style"; import { openRemote } from "#codebase/tcmts/cli/sync"; import type { RemoteConfig } from "#codebase/tcmts/cli/sync"; import { parse } from "@bomb.sh/router"; export async function runUser({ cb, cmd, rest }: Context): Promise<number> { const r = execute(cmd, parse(routeUser(), { argv: rest })); const on = r.model.remote; const { remote } = openRemote(cb, on); if (r.route === "/add") { const handle = r.model.handle.replace(/^@/, ""); const token = await remote.addUser(handle); const configured = cb.store.getSetting(`remote.${on}`); const url = configured ? (JSON.parse(configured) as RemoteConfig).url : on; console.log( `${green("added")} ${bold(`@${handle}`)} on ${on}: they push branches under @${handle}/ and propose them`, ); console.log(` their token (shown once; adding them again makes a new one): ${token}`); console.log( dim( ` they connect with: tcm remote add ${/^[\w.-]+$/.test(on) ? on : "origin"} ${url} --token ${token}`, ), ); return 0; } if (r.route === "/rm") { const handle = r.model.handle.replace(/^@/, ""); const removed = await remote.removeUser(handle); console.log( removed ? `removed @${handle} from ${on}: their token no longer works` : `${on} has no user @${handle}`, ); return removed ? 0 : 1; } const me = await remote.whoami(); if (me.role === "contributor") { console.log( `you're ${bold(`@${me.handle}`)} on ${on}: you push branches under @${me.handle}/ and propose them (\`tcm contribute\`)`, ); return 0; } if (me.role === "reader") { console.log( `you have no token for ${on}: you can pull and read contributions; its maintainer can make you one (\`tcm user add <handle>\`)`, ); return 0; } console.log(`you're ${on}'s maintainer`); const users = await remote.users(); if (!users.length) console.log(dim(" no contributors yet: `tcm user add <handle>` adds one")); for (const u of users) console.log( ` ${bold(`@${u.handle}`)} ${dim(`added ${new Date(u.added).toISOString().slice(0, 10)}`)}`, ); return 0; }
uses
- tcmts.cli.commands.routeUser
- tcmts.cli.main.execute
- tcmts.cli.run.Context
- tcmts.cli.style.bold
- tcmts.cli.style.dim
- tcmts.cli.style.green
- tcmts.cli.sync.RemoteConfig
- tcmts.cli.sync.openRemote