-
Notifications
You must be signed in to change notification settings - Fork 338
/
manifest.go
52 lines (44 loc) · 1.13 KB
/
manifest.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
/*----------------------------------------------------------------
* Copyright (c) ThoughtWorks, Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE in the project root for license information.
*----------------------------------------------------------------*/
package manifest
import (
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"github.com/getgauge/common"
"github.com/getgauge/gauge/config"
)
type Manifest struct {
Language string
Plugins []string
EnvironmentDir string
}
func ProjectManifest() (*Manifest, error) {
contents, err := common.ReadFileContents(filepath.Join(config.ProjectRoot, common.ManifestFile))
if err != nil {
return nil, err
}
dec := json.NewDecoder(strings.NewReader(contents))
var m Manifest
for {
if err := dec.Decode(&m); err == io.EOF {
break
} else if err != nil {
return nil, fmt.Errorf("Failed to read Manifest. %s\n", err.Error())
}
}
return &m, nil
}
func (m *Manifest) Save() error {
b, err := json.MarshalIndent(m, "", " ")
if err != nil {
return err
}
return os.WriteFile(common.ManifestFile, b, common.NewFilePermissions)
}