forked from snd/fragments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.coffee
130 lines (124 loc) · 3.43 KB
/
command.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
fragments = require '../src/fragments'
hinoki = require 'hinoki'
example = require '../example/app'
module.exports =
# 'getCommandNamesFromLifetime': (test) ->
# fragments (
# fragments_getCommandNamesFromLifetime
# ) ->
# lifetime =
# factories:
# command_app_myCommand: ->
# command_app_myOtherCommand: ->
# command_pg_migrate: ->
# test.deepEqual fragments_getCommandNamesFromLifetime(lifetime),
# [
# 'app:my-command',
# 'app:my-other-command'
# 'pg:migrate'
# ]
# test.done()
'unrecognized command': (test) ->
app = fragments()
app (
fragments_runCommand
) ->
try
fragments_runCommand 'app:my-command'
catch e
test.equal e.message, 'no such command: app:my-command'
test.done()
'recognized command': (test) ->
app = fragments [
fragments.source
{
command_app_myCommand: ->
(arg1, arg2) ->
test.equal arg1, value1
test.equal arg2, value2
test.done()
}
]
value1 = {}
value2 = {}
app (
fragments_runCommand
) ->
fragments_runCommand 'app:my-command', value1, value2
# 'getCommandHelpLinesFromLifetime': (test) ->
# app = fragments()
# app (
# getCommandHelpLinesFromLifetime
# ) ->
# lifetime =
# factories:
# command_bravo_charlie: ->
# command_alpha: ->
# command_alpha_bravo: ->
# command_bravo_alpha: ->
# command_alpha_bravo_charlie: ->
# command_bravo_bravo: ->
# command_bravo_charlie: ->
# command_delta_bravo_alpha: ->
# command_delta_bravo_echo: ->
# command_echo_delta: ->
# lifetime.factories.command_bravo_charlie.$help = 'does something'
# lifetime.factories.command_delta_bravo_alpha.$help = 'does something else'
#
# test.deepEqual getCommandHelpLinesFromLifetime(lifetime),
# [
# 'alpha'
# 'alpha:bravo'
# 'alpha:bravo:charlie'
# 'bravo:alpha'
# 'bravo:bravo'
# 'bravo:charlie does something'
# 'delta:bravo:alpha does something else'
# 'delta:bravo:echo'
# 'echo:delta'
# ]
#
# test.deepEqual getCommandHelpLinesFromLifetime(lifetime, 'bravo'),
# [
# 'bravo:alpha'
# 'bravo:bravo'
# 'bravo:charlie does something'
# ]
#
# test.deepEqual getCommandHelpLinesFromLifetime(lifetime, 'delta', 'bravo'),
# [
# 'delta:bravo:alpha does something else'
# 'delta:bravo:echo'
# ]
#
# test.deepEqual getCommandHelpLinesFromLifetime(lifetime, 'delta:bravo'),
# [
# 'delta:bravo:alpha does something else'
# 'delta:bravo:echo'
# ]
#
# test.deepEqual getCommandHelpLinesFromLifetime(lifetime, 'echo:delta'),
# [
# 'echo:delta'
# ]
# test.done()
'start and stop default server': (test) ->
example (
command_serve
fragments_shutdown
) ->
command_serve()
.then ->
fragments_shutdown()
.then ->
test.done()
'start and stop custom server': (test) ->
example (
command_serve
shutdown
) ->
command_serve('helloWorldServer')
.then ->
shutdown()
.then ->
test.done()