-
Notifications
You must be signed in to change notification settings - Fork 1
/
tidy.go
52 lines (42 loc) · 967 Bytes
/
tidy.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
package commands
import (
"encoding/json"
"os"
"github.com/Glow-Project/ppm/pkg/utility"
"github.com/urfave/cli/v2"
)
func tidy(ctx *cli.Context) error {
paths, err := utility.CreatePathsFromCwd()
if err != nil {
return err
}
content, err := os.ReadFile(paths.ConfigFile)
if err != nil {
return err
}
var jsonContent map[string]interface{}
err = json.Unmarshal(content, &jsonContent)
if err != nil {
return err
}
strDeps, ok := jsonContent["dependencies"].([]interface{})
if !ok {
return nil
}
deps := []*utility.Dependency{}
for _, dep := range strDeps {
str, ok := dep.(string)
if !ok {
return nil
}
deps = append(deps, utility.DependencyFromString(str))
}
jsonContent["dependencies"] = deps
jsonData, err := json.MarshalIndent(jsonContent, "", "\t")
os.WriteFile(paths.ConfigFile, jsonData, 0644)
config, err := utility.ParsePpmConfig(paths.ConfigFile)
if err != nil {
return err
}
return config.Write()
}