Navigation Menu

Skip to content

adamjosefus/allo_arguments

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Allo Arguments for Deno πŸ¦•

A library for Deno that parses the terminal's input parameters. It allows you to assign default values to them, process them and automatically generate a message for --help.

Example

import { join } from "https://deno.land/std/path/mod.ts";
import { Arguments, ExpectedException } from "https://deno.land/x/allo_arguments/mod.ts";


function getArguments() {
    const args = new Arguments({
        ...Arguments.createHelpOptions(),
        'myString': {
            shortName: 's',
            description: 'This is a string flag.',
            convertor: Arguments.stringConvertor,
        },
        'myNumber': {
            shortName: 'n',
            description: 'This is a number flag.',
            convertor: Arguments.numberConvertor,
            default: () => 0
        },
        'myBoolean': {
            shortName: 'b',
            description: 'This is a boolean flag.',
            convertor: Arguments.booleanConvertor,
        },
        'myCustom': {
            shortName: 'c',
            description: 'This is a custom flag.',
            convertor: value => {
                if (value === undefined) return undefined;

                return `🐰 β€” ${value} β€” 🐭`;
            },
        },
        'myDeprecated': {
            convertor: Arguments.stringConvertor,
            excludeFromHelp: true
        },
    })
    .setDescription("This is a demo of the arguments library.")


    // Important for `--help` flag works.
    if (args.isHelpRequested()) args.triggerHelp();

    return args.getFlags();
}


try {
    const args = getArguments();
    console.log(args);

} catch (error) {
    Arguments.rethrowUnprintableException(error);
}

Documentation πŸ“–

Description of all classes and methods will found in the documentation.


Check out other ours packages πŸ“¦!