forked from hashicorp/otto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.go
146 lines (123 loc) · 3.03 KB
/
commands.go
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package main
import (
"os"
"os/signal"
foundationConsul "github.com/hashicorp/otto/builtin/foundation/consul"
infraAws "github.com/hashicorp/otto/builtin/infra/aws"
"github.com/hashicorp/otto/builtin/pluginmap"
"github.com/hashicorp/otto/command"
"github.com/hashicorp/otto/foundation"
"github.com/hashicorp/otto/infrastructure"
"github.com/hashicorp/otto/otto"
"github.com/mitchellh/cli"
)
// Commands is the mapping of all the available Otto commands.
var Commands map[string]cli.CommandFactory
var CommandsInclude []string
// Ui is the cli.Ui used for communicating to the outside world.
var Ui cli.Ui
const (
ErrorPrefix = "e:"
OutputPrefix = "o:"
)
func init() {
Ui = &cli.ColoredUi{
OutputColor: cli.UiColorNone,
InfoColor: cli.UiColorNone,
ErrorColor: cli.UiColorRed,
WarnColor: cli.UiColorNone,
Ui: &cli.PrefixedUi{
AskPrefix: OutputPrefix,
OutputPrefix: OutputPrefix,
InfoPrefix: OutputPrefix,
ErrorPrefix: ErrorPrefix,
Ui: &cli.BasicUi{Writer: os.Stdout},
},
}
foundations := foundationConsul.Tuples.Map(foundation.StructFactory(new(foundationConsul.Foundation)))
meta := command.Meta{
CoreConfig: &otto.CoreConfig{
Foundations: foundations,
Infrastructures: map[string]infrastructure.Factory{
"aws": infraAws.Infra,
},
},
Ui: Ui,
PluginMap: pluginmap.Map,
}
CommandsInclude = []string{
"compile",
"build",
"deploy",
"dev",
"infra",
"status",
"version",
}
Commands = map[string]cli.CommandFactory{
"compile": func() (cli.Command, error) {
return &command.CompileCommand{
Meta: meta,
}, nil
},
"build": func() (cli.Command, error) {
return &command.BuildCommand{
Meta: meta,
}, nil
},
"deploy": func() (cli.Command, error) {
return &command.DeployCommand{
Meta: meta,
}, nil
},
"dev": func() (cli.Command, error) {
return &command.DevCommand{
Meta: meta,
}, nil
},
"infra": func() (cli.Command, error) {
return &command.InfraCommand{
Meta: meta,
}, nil
},
"status": func() (cli.Command, error) {
return &command.StatusCommand{
Meta: meta,
}, nil
},
"version": func() (cli.Command, error) {
return &command.VersionCommand{
Meta: meta,
Revision: GitCommit,
Version: Version,
VersionPrerelease: VersionPrerelease,
CheckFunc: commandVersionCheck,
}, nil
},
// Internal or not shown to users directly
"plugin-builtin": func() (cli.Command, error) {
return &command.PluginBuiltinCommand{
Meta: meta,
}, nil
},
"help": func() (cli.Command, error) {
return &command.HelpCommand{
Meta: meta,
}, nil
},
}
}
// makeShutdownCh creates an interrupt listener and returns a channel.
// A message will be sent on the channel for every interrupt received.
func makeShutdownCh() <-chan struct{} {
resultCh := make(chan struct{})
signalCh := make(chan os.Signal, 4)
signal.Notify(signalCh, os.Interrupt)
go func() {
for {
<-signalCh
resultCh <- struct{}{}
}
}()
return resultCh
}