forked from bitrise-io/bitrise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
normalize.go
50 lines (42 loc) · 1.42 KB
/
normalize.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
package cli
import (
log "github.com/Sirupsen/logrus"
"github.com/bitrise-io/bitrise/bitrise"
"github.com/urfave/cli"
)
func normalize(c *cli.Context) error {
// Expand cli.Context
bitriseConfigBase64Data := c.String(ConfigBase64Key)
bitriseConfigPath := c.String(ConfigKey)
deprecatedBitriseConfigPath := c.String(PathKey)
if bitriseConfigPath == "" && deprecatedBitriseConfigPath != "" {
log.Warn("'path' key is deprecated, use 'config' instead!")
bitriseConfigPath = deprecatedBitriseConfigPath
}
//
// Input validation
bitriseConfigPath, err := GetBitriseConfigFilePath(bitriseConfigPath)
if err != nil {
log.Fatalf("Failed to get bitrise config path, error: %s", err)
}
if bitriseConfigPath == "" {
log.Fatal("No bitrise config path defined!")
}
// Config validation
bitriseConfig, warnings, err := CreateBitriseConfigFromCLIParams(bitriseConfigBase64Data, bitriseConfigPath)
for _, warning := range warnings {
log.Warnf("warning: %s", warning)
}
if err != nil {
log.Fatalf("Failed to create bitrise config, error: %s", err)
}
// Normalize
if err := bitrise.RemoveConfigRedundantFieldsAndFillStepOutputs(&bitriseConfig); err != nil {
log.Fatalf("Failed to remove redundant fields, error: %s", err)
}
if err := bitrise.SaveConfigToFile(bitriseConfigPath, bitriseConfig); err != nil {
log.Fatalf("Failed to save config to file, error: %s", err)
}
log.Info("Redundant fields removed")
return nil
}