-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6948854
commit ac51bc9
Showing
5 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<GreetParams> { | ||
async execute(params: GreetParams) { | ||
console.log(`Hello ${params.name}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<LoginParams> { | ||
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`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as cli from '../src'; | ||
|
||
import './commands/greet'; | ||
import './commands/login'; | ||
|
||
cli.execute(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true | ||
}, | ||
"extends": "../tsconfig.json", | ||
"files": [ | ||
"./index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters