Adding cli commands to your app

To add a cli command to your app, you'll need to add a run method to your app's default export.

// File: ~/smallweb/custom-command/main.ts
export default {
    run(args: string[]) {
        console.log("Hello world");
    }
}

Use smallweb run to execute the command:

$ smallweb run custom-command
Hello world

Using a cli framework

Cliffy is an excellent Deno CLI framework that you can use to build more complex CLI applications.

You can easily wire it to smallweb:

import { Command } from "jsr:@cliffy/[email protected]";

const name = basename(Deno.cwd());
const command = new Command().name().action(() => {
    console.log(`Hello ${name}`);
});

export default {
    run(args: string[]) {
        await command.parse(args);
    }
}