1.1.2•Updated a month ago
import { type Command, GetCommand } from "./commands/enum.ts";
import { help_command } from "./commands/help.command.ts";
import { status_command } from "./commands/status.command.ts";
import { publish_command } from "./commands/publish.command.ts";
import type { Option } from "./options.ts";
import { run_command } from "./commands/run.command.ts";
import { update_command } from "./commands/update.command.ts";
import { install_command } from "./commands/install.command.ts";
interface I_Command {
name: string
options: Record<string, any>
args: any[]
}
export interface I_CommandCode {
command: Command,
aliases?: string[],
description: string,
more_info?: string[],
help_text: string[]
optional_options?: Option[],
execute: (cmd: I_Command) => void
}
export const CommandCodes: I_CommandCode[] = [
help_command,
status_command,
publish_command,
run_command,
update_command,
install_command,
]
export const RunCommand = async (cmd: I_Command) => {
try {
if(!cmd.name) throw new Error('No command provided');
const cmd_name = cmd.name.toString().toLowerCase();
const command = CommandCodes.find(command_code => {
return GetCommand(command_code.command) == cmd_name || command_code.aliases?.includes(cmd_name);
});
if(!command) {
throw new Error(`Command not found! [${cmd_name}]`);
}
await command.execute(cmd);
Deno.exit(0);
} catch(e: any) {
console.warn(`Viapak - ${e.message}`);
console.warn(` Use viapak --help to see a list of available commans.`);
Deno.exit(0);
}
}