Skip to content

neverUsedGithub/Argue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Argue

Modern argument parsing, with colors, made easy.

Installation

npm i https://github.com/neverUsedGithub/Argue

Usage

Basics

import argue from "argue";

const ctx = 
    argue({
        name: "greeter"
    })
    .opt({
        name: "-n, --name",
        accepts: "string",
        default: "World"
    })
    .parse(process.argv.slice(2));

// Argue automatically created argv with the correct types
console.log(ctx.argv.name);

Advanced

const ctx =
    argue({
        name: "server",
        describe: "A server cli.",
    })
    .command({
        name: "serve",
        help: "serve [port]",
        describe: "Start a server on the specified port."
    }, argue => argue
        .pos({
            name: "port",
            describe: "The port to listen on.",
            accepts: "number",
            default: 3000
        })
    )
    .opt({
        name: "-v, --verbose",
        describe: "Use verbose logging.",
        accepts: "boolean",
        default: false
    })
    .parse(process.argv.slice(2));

if (ctx.command === "none")
    console.log(ctx.argv.port) // errors

// ctx.command is the command that was used or "none"
console.log(
    ctx.command /* "none" | "serve" */,
    ctx.argv /* { verbose: boolean } | { port: number } */
);

About

Modern argument parsing, with colors, made easy.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published