Home / Function/ cli() — astro Function Reference

cli() — astro Function Reference

Architecture documentation for the cli() function in index.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  eebbb6d3_b44c_20dc_b02b_302b51975286["cli()"]
  2294057a_aeb5_9170_f933_78f104855727["index.ts"]
  eebbb6d3_b44c_20dc_b02b_302b51975286 -->|defined in| 2294057a_aeb5_9170_f933_78f104855727
  3bf65f9e_3c0f_fac3_a2eb_1559637034c2["validateDbAppTokenFlag()"]
  eebbb6d3_b44c_20dc_b02b_302b51975286 -->|calls| 3bf65f9e_3c0f_fac3_a2eb_1559637034c2
  style eebbb6d3_b44c_20dc_b02b_302b51975286 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/db/src/core/cli/index.ts lines 6–71

export async function cli({
	flags,
	config: astroConfig,
}: {
	flags: Arguments;
	config: AstroConfig;
}) {
	const args = flags._ as string[];
	// Most commands are `astro db foo`, but for now login/logout
	// are also handled by this package, so first check if this is a db command.
	const command = args[2] === 'db' ? args[3] : args[2];
	validateDbAppTokenFlag(command, flags);
	const { dbConfig } = await resolveDbConfig(astroConfig);

	switch (command) {
		case 'shell': {
			const { cmd } = await import('./commands/shell/index.js');
			return await cmd({ astroConfig, dbConfig, flags });
		}
		case 'gen': {
			console.log('"astro db gen" is no longer needed! Visit the docs for more information.');
			return;
		}
		case 'sync': {
			console.log('"astro db sync" is no longer needed! Visit the docs for more information.');
			return;
		}
		case 'push': {
			const { cmd } = await import('./commands/push/index.js');
			return await cmd({ astroConfig, dbConfig, flags });
		}
		case 'verify': {
			const { cmd } = await import('./commands/verify/index.js');
			return await cmd({ astroConfig, dbConfig, flags });
		}
		case 'execute': {
			const { cmd } = await import('./commands/execute/index.js');
			return await cmd({ astroConfig, dbConfig, flags });
		}
		default: {
			if (command != null) {
				console.error(`Unknown command: ${command}`);
			}
			printHelp({
				commandName: 'astro db',
				usage: '[command] [...flags]',
				headline: ' ',
				tables: {
					Commands: [
						['push', 'Push table schema updates to libSQL.'],
						['verify', 'Test schema updates with libSQL (good for CI).'],
						[
							'astro db execute <file-path>',
							'Execute a ts/js file using astro:db. Use --remote to connect to libSQL.',
						],
						[
							'astro db shell --query <sql-string>',
							'Execute a SQL string. Use --remote to connect to libSQL.',
						],
					],
				},
			});
			return;
		}
	}
}

Domain

Subdomains

Frequently Asked Questions

What does cli() do?
cli() is a function in the astro codebase, defined in packages/db/src/core/cli/index.ts.
Where is cli() defined?
cli() is defined in packages/db/src/core/cli/index.ts at line 6.
What does cli() call?
cli() calls 1 function(s): validateDbAppTokenFlag.

Analyze Your Own Codebase

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

Try Supermodel Free