Home / File/ print-help.ts — astro Source File

print-help.ts — astro Source File

Architecture documentation for print-help.ts, a typescript file in the astro codebase. 1 imports, 0 dependents.

File typescript CoreAstro CoreMiddleware 1 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  b51da42f_0188_29dd_0781_7217261187d6["print-help.ts"]
  10250468_0e83_bd69_43e9_3bcef2294a91["piccolore"]
  b51da42f_0188_29dd_0781_7217261187d6 --> 10250468_0e83_bd69_43e9_3bcef2294a91
  style b51da42f_0188_29dd_0781_7217261187d6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import colors from 'piccolore';

/**
 * Uses implementation from Astro core
 * @see https://github.com/withastro/astro/blob/main/packages/astro/src/core/messages.ts#L303
 */
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

Functions

Dependencies

  • piccolore

Frequently Asked Questions

What does print-help.ts do?
print-help.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, CoreMiddleware subdomain.
What functions are defined in print-help.ts?
print-help.ts defines 1 function(s): printHelp.
What does print-help.ts depend on?
print-help.ts imports 1 module(s): piccolore.
Where is print-help.ts in the architecture?
print-help.ts is located at packages/db/src/core/cli/print-help.ts (domain: CoreAstro, subdomain: CoreMiddleware, directory: packages/db/src/core/cli).

Analyze Your Own Codebase

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

Try Supermodel Free