forked from hashicorp/otto
/
dev.go
98 lines (79 loc) · 2.14 KB
/
dev.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
package command
import (
"fmt"
"strings"
"github.com/hashicorp/otto/helper/flag"
"github.com/hashicorp/otto/otto"
)
// DevCommand is the command that manages (starts, stops, etc.) the
// development environment for an Appfile.
type DevCommand struct {
Meta
}
func (c *DevCommand) Run(args []string) int {
fs := c.FlagSet("dev", FlagSetNone)
fs.Usage = func() { c.Ui.Error(c.Help()) }
args, execArgs, posArgs := flag.FilterArgs(fs, args)
if err := fs.Parse(args); err != nil {
return 1
}
// Get the remaining args to determine if we have an action.
var action string
if len(posArgs) > 0 {
action = posArgs[0]
execArgs = append(execArgs, posArgs[1:]...)
}
// Load the appfile
app, err := c.Appfile()
if err != nil {
c.Ui.Error(err.Error())
return 1
}
// Get a core
core, err := c.Core(app)
if err != nil {
c.Ui.Error(fmt.Sprintf(
"Error loading core: %s", err))
return 1
}
// If we have an action, then we use Execute(). Otherwise, we're
// building the dev environment with Dev().
if action == "" {
// Build the development environment
if err := core.Dev(); err != nil {
c.Ui.Error(fmt.Sprintf(
"Error building dev environment: %s", err))
return 1
}
return 0
}
// Execute the task
err = core.Execute(&otto.ExecuteOpts{
Task: otto.ExecuteTaskDev,
Action: action,
Args: execArgs,
})
if err != nil {
c.Ui.Error(err.Error())
return 1
}
return 0
}
func (c *DevCommand) Synopsis() string {
return "Start and manage a development environment"
}
func (c *DevCommand) Help() string {
helpText := `
Usage: otto dev [subcommand] [options]
Start and manage a development environment for your application.
This will start a development environment for your application.
Additional subcommands such as "destroy" can be given to tear down
the development environment.
The development environment will be local and will automatically include
all upstream dependencies within the environment properly configured
and started.
The list of available subcommands depends on the type of application
you're developing. To see the list, run "otto dev help".
`
return strings.TrimSpace(helpText)
}