/
createfolder.go
59 lines (50 loc) · 1.59 KB
/
createfolder.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
package step
import (
"fmt"
"github.com/ChristianHuff-DEV/reapy/model"
log "github.com/sirupsen/logrus"
"os"
)
// KindCreateFolder defines the name for a create folder step in the config file
const KindCreateFolder = "CreateFolder"
// CreateFolder is a step that is used to create a folder
type CreateFolder struct {
model.RunnableStep
Path string
}
// FromConfig create the struct representation of a step creating a folder
func (createFolder *CreateFolder) FromConfig(configYaml map[string]interface{}) error {
createFolder.Kind = KindCreateFolder
if description, ok := configYaml["Description"]; ok {
createFolder.Description = description.(string)
}
preferencesYaml := configYaml["Preferences"].(map[string]interface{})
createFolder.Path = preferencesYaml["Path"].(string)
return nil
}
// GetKind returns the type this step is of
func (createFolder CreateFolder) GetKind() string {
return createFolder.Kind
}
// GetDescription returns a summary of what this step does
func (createFolder CreateFolder) GetDescription() string {
return createFolder.Description
}
// Execute create a folder at a defined path
func (createFolder CreateFolder) Execute() model.Result {
fmt.Println(createFolder.Description)
log.Printf("Creating %s", createFolder.Path)
return create(createFolder.Path)
}
// Create makes a new folder at the given path
func create(path string) (result model.Result) {
err := os.MkdirAll(path, os.ModePerm)
if err != nil {
result.WasSuccessful = false
result.Message = err.Error()
return result
}
result.WasSuccessful = true
result.Message = "folder created"
return result
}