From 9528acf0ce479810b07f894cb7fde01e37501343 Mon Sep 17 00:00:00 2001 From: Michael Inthilith Date: Tue, 19 Feb 2019 00:37:30 +0100 Subject: [PATCH] fix($compile): Extended ts type for logger Logger interface handle many input types that were not supported. Also added a basic ts example. --- README.md | 26 ++++++++++++++++++++++++++ examples/pizza/package.json | 10 +++++++--- examples/pizza/typescript.ts | 17 +++++++++++++++++ index.d.ts | 15 ++++++++++----- 4 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 examples/pizza/typescript.ts diff --git a/README.md b/README.md index d11182e..cc441bf 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,32 @@ prog.parse(process.argv); // ./myprog deploy myapp production --tail 100 ``` +Or else if you prefer `typescript` +```javascript +#!/usr/bin/env node +import * as prog from 'caporal'; +prog + .version('1.0.0') + // you specify arguments using .argument() + // 'app' is required, 'env' is optional + .command('deploy', 'Deploy an application') + .argument('', 'App to deploy', /^myapp|their-app$/) + .argument('[env]', 'Environment to deploy on', /^dev|staging|production$/, 'local') + // you specify options using .option() + // if --tail is passed, its value is required + .option('--tail ', 'Tail lines of logs after deploy', prog.INT) + .action(function(args, options, logger) { + // args and options are objects + // args = {"app": "myapp", "env": "production"} + // options = {"tail" : 100} + }); + +prog.parse(process.argv); + +// ./myprog deploy myapp production --tail 100 +``` + + ### Variadic arguments You can use `...` to indicate variadic arguments. In that case, the resulted value will be an array. diff --git a/examples/pizza/package.json b/examples/pizza/package.json index 2142bc1..c787c1b 100644 --- a/examples/pizza/package.json +++ b/examples/pizza/package.json @@ -6,10 +6,14 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, - "dependencies" : { - "caporal": "file:../../" + "dependencies": { + "@types/node": "^11.9.4", + "caporal": "file:../../", + "tsc": "^1.20150623.0" + }, + "bin": { + "fly": "./pizza.js" }, - "bin" : { "fly" : "./pizza.js" }, "author": "", "license": "ISC" } diff --git a/examples/pizza/typescript.ts b/examples/pizza/typescript.ts new file mode 100644 index 0000000..9e5cb77 --- /dev/null +++ b/examples/pizza/typescript.ts @@ -0,0 +1,17 @@ +import * as prog from 'caporal'; + +prog + .version('1.0.0') + // you specify arguments using .argument() + // 'app' is required, 'env' is optional + .command('ts', 'Basic typescript example') + .argument('[arg]', 'argument desc', /^.*$/, 'default arg') + .option('--option