python-clickjs
v0.0.2
Published
JS port of fabulous Python click argument parsing library
Readme
clickjs
JavaScript port of famous Python click library for argument parsing
Table of Contents
Installation
Install the package npm:
$ npm install clickjs --saveAlternatively if you are using yarn:
$ yarn add clickjsEnabling 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.
