-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_create.go
44 lines (38 loc) · 991 Bytes
/
command_create.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
package main
import (
"github.com/perrito666/goworkon/actions"
"github.com/perrito666/goworkon/environment"
"github.com/pkg/errors"
)
// Create command allows for the creation of environments.
type Create struct {
environmentName string
goVersion string
goPath string
settings environment.Settings
}
// Usage implements Command.
func (c Create) Usage() string {
return "the expected format is: goworkon [Options] create <envname>"
}
// Validate implements Command.
func (c Create) Validate() error {
if c.environmentName == "" {
return errors.New("missing environment name")
}
if c.goVersion == "" {
return errors.New("missing go version")
}
if c.goPath == "" {
return errors.New("missing gopath/workspace for the environment")
}
return nil
}
// Run implements Command.
func (c Create) Run() error {
err := actions.Create(c.environmentName, c.goVersion, c.goPath, c.settings)
if err != nil {
return errors.WithStack(err)
}
return nil
}