Skip to content

JavaScript composable command line interface toolkit

License

Notifications You must be signed in to change notification settings

saskaale/clickjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clickjs

JavaScript port of famous Python click library for argument parsing Build Status

Table of Contents

Installation

Install the package npm:

$ npm install python-clickjs --save

Alternatively if you are using yarn:

$ yarn add python-clickjs

Enabling decorators

TypeScript

Enable the compiler option experimentalDecorators in tsconfig.json or pass it as flag --experimentalDecorators to the compiler.

Babel 7.x:

Install support for decorators: npm i --save-dev @babel/plugin-proposal-class-properties @babel/plugin-proposal-decorators. And enable it in your .babelrc file:

{
    "presets": ["@babel/preset-env"],
    "plugins": [
        ["@babel/plugin-proposal-decorators", { "legacy": true}],
        ["@babel/plugin-proposal-class-properties", { "loose": true}]
    ]
}

Babel 6.x:

Install support for decorators: npm i --save-dev babel-plugin-transform-decorators-legacy. And enable it in your .babelrc file:

{
    "presets": ["es2015", "stage-1"],
    "plugins": ["transform-decorators-legacy"]
}

Babel 5.x

 {
   "stage": 1
 }

Probably you have more plugins and presets in your .babelrc already, note that the order is important and transform-decorators-legacy should come as first.

Usage

import Click from 'clickjs';

@Click.group()
class Command{
    @Click.command("2")
    @Click.argument("value")
    @Click.argument("value2")
    evaluate2(params){
        console.log("command run 2()")
        console.log(params);
    }

    @Click.command("1")
    @Click.option("name")
    @Click.option("name2", {default: '12'})
    evaluate1(params){
        console.log("command run 1()");
        console.log(params);
    }
}

@Command.group("3")
class SubCommand{
    @Click.command("2")
    evaluate2(params){
        console.log("command run 3-2()");
        console.log(params);
    }

    @Click.command("1")
    @Click.option("name")
    @Click.option("name2", {default: '12'})
    evaluate1(params){
        console.log("command run 3-1()");
        console.log(params);
    }
}

new Command().run();

License

This code has been released under the Apache 2.0 License.

About

JavaScript composable command line interface toolkit

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages