This repository was archived by the owner on Oct 16, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +51
-2
lines changed Expand file tree Collapse file tree 3 files changed +51
-2
lines changed Original file line number Diff line number Diff line change 1+ // @ flow
2+
3+ import Command from 'cli-engine-command'
4+ import DurationMixin from '../mixins/duration'
5+
6+ export default class extends DurationMixin ( Command ) {
7+ static topic = 'cli'
8+ static command = 'duration'
9+ static description = 'this is an example command showing duration parsing'
10+
11+ static flags = [
12+ { name : 'foo' }
13+ ]
14+
15+ run ( ) {
16+ this . log ( `duration: ${ this . duration } ` )
17+ }
18+ }
Original file line number Diff line number Diff line change @@ -4,5 +4,7 @@ export const topics = [
44 { name : 'cli' , description : 'example CLI engine topic' }
55]
66
7- import CLI from './commands/cli'
8- export const commands = [ CLI ]
7+ export const commands = [
8+ require ( './commands/cli' ) ,
9+ require ( './commands/duration' )
10+ ]
Original file line number Diff line number Diff line change 1+ // @flow
2+
3+ import Command , { type Flag } from 'cli-engine-command' // eslint-disable-line
4+
5+ const FLAG : Flag = {
6+ name : 'duration' ,
7+ description : 'a duration' ,
8+ required : true ,
9+ hasValue : true
10+ }
11+
12+ declare class App extends Command {
13+ duration : Date
14+ }
15+
16+ export default function < T : Class < Command > > ( Base : T ) : $Shape < Class < App >> {
17+ return class DurationMixin extends Base {
18+ static get flags ( ) : Flag [ ] { return this . _flags . concat ( [ FLAG ] ) }
19+ static set flags ( flags : Flag [ ] ) { this . _flags = flags }
20+
21+ get duration ( ) : Date {
22+ this . inspect ( this . constructor . flags )
23+
24+ // this is a little gross but I think needed to cast it to a string
25+ let duration = ( ( ( this . flags . duration ) : any ) : string )
26+ return new Date ( duration )
27+ }
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments