Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix($compile): Extended ts type for logger #134

Merged
merged 1 commit into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>', '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 <lines>', 'Tail <lines> 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.
Expand Down
10 changes: 7 additions & 3 deletions examples/pizza/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
17 changes: 17 additions & 0 deletions examples/pizza/typescript.ts
Original file line number Diff line number Diff line change
@@ -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 <option>', 'option desc', prog.STRING, 'default option')
.action((args, options, logger) => {
logger.info('Hello');
logger.info(options);
logger.info("%j", args);
});


prog.parse(process.argv);
15 changes: 10 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@ type ValidatorArg = string[]|string|RegExp|ValidatorFn|Number;
type ValidatorFn = (str: string) => any;

declare interface Logger {
debug(str: string): void;
info(str: string): void;
log(str: string): void;
warn(str: string): void;
error(str: string): void;
debug(str: string|object): void;
debug(format: string, ...mixed: any[]): void;
info(str: string|object): void;
info(format: string, ...mixed: any[]): void;
log(str: string|object): void;
log(format: string, ...mixed: any[]): void;
warn(str: string|object): void;
warn(format: string, ...mixed: any[]): void;
error(str: string|object): void;
error(format: string, ...mixed: any[]): void;
}

declare interface Command {
Expand Down