diff --git a/example/commands/greet.ts b/example/commands/greet.ts new file mode 100644 index 0000000..c23d711 --- /dev/null +++ b/example/commands/greet.ts @@ -0,0 +1,14 @@ +// tslint:disable:no-console +import { Command, command, value } from '../../src'; + +export class GreetParams { + @value() + name: string = ''; +} + +@command('greet', GreetParams) +export class Greet implements Command { + async execute(params: GreetParams) { + console.log(`Hello ${params.name}`); + } +} diff --git a/example/commands/login.ts b/example/commands/login.ts new file mode 100644 index 0000000..0ef73e0 --- /dev/null +++ b/example/commands/login.ts @@ -0,0 +1,30 @@ +// tslint:disable:no-console +import { Command, command, option, value } from '../../src'; + +export class LoginParams { + @value() + username: string = ''; + + @value({ optional: true }) + password: string = ''; + + @option({ valueName: 'days', description: 'Number of days to keep user logged in for' }) + rememberMeFor: number = 1; +} + +@command('login', LoginParams) +export class LoginCommand implements Command { + async execute(params: LoginParams) { + if (params.username.toLowerCase() !== 'guest') { + if (params.password !== 'Password123') { + return console.error('Password incorrect'); + } + } + + console.log(`Authenticated. Welcome ${params.username}`); + + if (params.rememberMeFor) { + console.log(`Session will be kept alive for ${params.rememberMeFor} days`); + } + } +} diff --git a/example/index.ts b/example/index.ts new file mode 100644 index 0000000..41c68b5 --- /dev/null +++ b/example/index.ts @@ -0,0 +1,6 @@ +import * as cli from '../src'; + +import './commands/greet'; +import './commands/login'; + +cli.execute(); diff --git a/example/tsconfig.json b/example/tsconfig.json new file mode 100644 index 0000000..709c216 --- /dev/null +++ b/example/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true + }, + "extends": "../tsconfig.json", + "files": [ + "./index.ts" + ] +} diff --git a/package.json b/package.json index cac622d..b1e5e9d 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "build": "tsc -p ./", "clean": "rimraf ./dist", "commit": "commit", - "preexample": "npm run package", "example": "ts-node ./example", "lint": "tslint -p ./tsconfig.json", "lint:fix": "npm run lint -- --fix",