Git Product home page Git Product logo

litargs's Introduction

Litargs


typescript node.js npm npm GitHub issues GitHub forks GitHub stars GitHub license

Would you like to parse arguments more easily?

Highlights:flashlight:

  • The easiest CLI command line parser
  • Recommended for those who want simple parsing results
  • Easy to set options
  • Automatically create help

Install

npm install litargs

Usage

  • index.js
//Example of a command to move a file
const { Litargs } = require('litargs');
const fs = require('fs');

Litargs.command(
    'move',
    2,
    { args: ['source', 'destination'], detail: 'Move a file' },
    (args, option) => {
        if (option.cp) {
            fs.copyFileSync(args[0], args[1]);
        } else {
            fs.renameSync(args[0], args[1]);
        }
    }
)
    .option('cp', 0, { detail: 'copy' })
    .parse(process.argv.slice(2).join(' '));

Litargs.execute();
  • Command Line
$ node index.js move /Users/hoge.txt /Users/fuga.txt --cp
  • help
Commands:
help                    Display a list of commands and options


move    [source, destination]   Move a file
        Options:
        --cp                    copy

API

Litargs.command(name<string>, argumentCount<number>, description<{args?: string[], detail: string}>, handler<(args<string>, option<{[optionName: string]: string[]|boolean>}): unknown>)

Add the command. Arguments are the name of the command, the number of arguments, a description of the command, and the function to be executed. The handler can accept arguments and options. For description, set the name of the argument in args and a concrete description in detail. If the expected number of arguments is 0, there is no need to set args.

Litargs.option(name<string>, argumentCount<number>, description<args?: string[], detail: string>)

Commands and options are added in the method chain.

Litargs.command(...).option(...).option(...).command(...).option(...)...

The option method will be applied to the last command added. The basic settings are the same as for the command method. Options that require arguments are prefixed with "-", and options that do not require arguments are prefixed with "--". This does not need to be attached to "name", but it is required on the command line.

Litargs.alias(name<string>)

The alias method will be applied to the last command added. You can give different names to the commands.

Litargs.parse(parsedString<string>)

Add this to the end of the method chain. For use with the node.js cli, specify process.argv.slice(2).join(' '). This method returns a simple parsing result.

Litargs.execute()

Execute the registered handler. This should not be done before parse.

Issues

If you find a bug or problem, please open an issue!:bug:

Author

LICENSE

This project is licensed under the MIT License - see the LICENSE file for details.

litargs's People

Contributors

airrnot1106 avatar

Stargazers

Andrew Johnson avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.