Home / Function/ printHelp() — astro Function Reference

printHelp() — astro Function Reference

Architecture documentation for the printHelp() function in print-help.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  5116cacc_c416_10e5_9380_54e816847ce6["printHelp()"]
  b51da42f_0188_29dd_0781_7217261187d6["print-help.ts"]
  5116cacc_c416_10e5_9380_54e816847ce6 -->|defined in| b51da42f_0188_29dd_0781_7217261187d6
  style 5116cacc_c416_10e5_9380_54e816847ce6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/db/src/core/cli/print-help.ts lines 7–69

export function printHelp({
	commandName,
	headline,
	usage,
	tables,
	description,
}: {
	commandName: string;
	headline?: string;
	usage?: string;
	tables?: Record<string, [command: string, help: string][]>;
	description?: string;
}) {
	const linebreak = () => '';
	const title = (label: string) => `  ${colors.bgWhite(colors.black(` ${label} `))}`;
	const table = (rows: [string, string][], { padding }: { padding: number }) => {
		const split = process.stdout.columns < 60;
		let raw = '';

		for (const row of rows) {
			if (split) {
				raw += `    ${row[0]}\n    `;
			} else {
				raw += `${`${row[0]}`.padStart(padding)}`;
			}
			raw += '  ' + colors.dim(row[1]) + '\n';
		}

		return raw.slice(0, -1); // remove latest \n
	};

	let message = [];

	if (headline) {
		message.push(
			linebreak(),
			`  ${colors.bgGreen(colors.black(` ${commandName} `))} ${colors.green(
				`v${process.env.PACKAGE_VERSION ?? ''}`,
			)} ${headline}`,
		);
	}

	if (usage) {
		message.push(linebreak(), `  ${colors.green(commandName)} ${colors.bold(usage)}`);
	}

	if (tables) {
		function calculateTablePadding(rows: [string, string][]) {
			return rows.reduce((val, [first]) => Math.max(val, first.length), 0) + 2;
		}
		const tableEntries = Object.entries(tables);
		const padding = Math.max(...tableEntries.map(([, rows]) => calculateTablePadding(rows)));
		for (const [tableTitle, tableRows] of tableEntries) {
			message.push(linebreak(), title(tableTitle), table(tableRows, { padding }));
		}
	}

	if (description) {
		message.push(linebreak(), `${description}`);
	}

	console.log(message.join('\n') + '\n');
}

Domain

Subdomains

Frequently Asked Questions

What does printHelp() do?
printHelp() is a function in the astro codebase, defined in packages/db/src/core/cli/print-help.ts.
Where is printHelp() defined?
printHelp() is defined in packages/db/src/core/cli/print-help.ts at line 7.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free