Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 2d8bd54

Browse files
author
Jeff Dickey
committed
[wip] added duration example
1 parent bcd67ae commit 2d8bd54

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

src/commands/duration.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff 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+
]

src/mixins/duration.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}

0 commit comments

Comments
 (0)