forked from ava-labs/avalanche-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy_status.go
45 lines (37 loc) · 1.15 KB
/
deploy_status.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
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package subnet
import (
"os"
"github.com/ava-labs/avalanche-cli/pkg/application"
"github.com/ava-labs/avalanche-cli/pkg/models"
"github.com/ava-labs/avalanche-cli/pkg/ux"
)
func GetLocallyDeployedSubnetsFromFile(app *application.Avalanche) ([]string, error) {
allSubnetDirs, err := os.ReadDir(app.GetSubnetDir())
if err != nil {
return nil, err
}
deployedSubnets := []string{}
for _, subnetDir := range allSubnetDirs {
if !subnetDir.IsDir() {
continue
}
// read sidecar file
sc, err := app.LoadSidecar(subnetDir.Name())
if err == os.ErrNotExist {
// don't fail on missing sidecar file, just warn
ux.Logger.PrintToUser("warning: inconsistent subnet directory. No sidecar file found for subnet %s", subnetDir.Name())
continue
}
if err != nil {
return nil, err
}
// check if sidecar contains local deployment info in Networks map
// if so, add to list of deployed subnets
if _, ok := sc.Networks[models.Local.String()]; ok {
deployedSubnets = append(deployedSubnets, sc.Name)
}
}
return deployedSubnets, nil
}