Skip to main content
Module

x/enzastdlib/commands/application.ts>makeApplication

enzastdlib is a set of TypeScript modules that follow a common design API philosophy aiming at sane defaults and ease-of-use targeting the Deno TypeScript runtime.
Latest
function makeApplication
import { makeApplication } from "https://deno.land/x/enzastdlib@v0.0.4/commands/application.ts";

Makes a new Application for handling command line parsing and validation via JSON Schema.

Examples

schema.ts

import type { JSONSchema, typeofschema } from 'https://deno.land/x/enzastdlib/schema/mod.ts';

export const MY_STRING_SCHEMA = {
    type: 'object',

    properties: {
        mystring: {
            type: 'string',

            minLength: 1,
        },
    },
} as const satisfies JSONSchema;

export type MyStringOptions = typeofschema<typeof MY_STRING_SCHEMA>;

mycommand.ts

import { assertEquals } from 'https://deno.land/std/testing/asserts.ts';
import { schema } from 'https://deno.land/x/enzastdlib/commands/mod.ts';

import type { MyStringOptions } from './schema.ts';
import { MY_STRING_SCHEMA } from './schema.ts';

schema(mycommand, MY_STRING_SCHEMA);
export function mycommand(options: MyStringOptions): void {
    assertEquals(
        options,
        { mystring: 'Hello World!' },
    );
}

mod.ts

import { makeApplication } from 'https://deno.land/x/enzastdlib/commands/mod.ts';

import { mycommand } from './mycommand.ts';

const application = makeApplication({
    // NOTE: If we compiled your application via `deno compile` then you should
    // use your binary's name here.
    name: 'deno run ./mod.ts',
    description: 'I run cool subcommands!',

    commands: {
        mycommand,
    },
});

const exit_code = await application.handleArgs(Deno.arg);
Deno.exit(exit_code);

terminal

deno run ./mod.ts --mystring "Hello World!"