-
Notifications
You must be signed in to change notification settings - Fork 60
/
import.go
60 lines (48 loc) · 1.58 KB
/
import.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
60
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package upgradecmd
import (
"fmt"
"os"
"github.com/ava-labs/avalanche-cli/pkg/ux"
"github.com/spf13/cobra"
)
var upgradeBytesFilePath string
const upgradeBytesFilePathKey = "upgrade-filepath"
// avalanche subnet upgrade import
func newUpgradeImportCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "import [subnetName]",
Short: "Import the upgrade bytes file into the local environment",
Long: `Import the upgrade bytes file into the local environment`,
RunE: upgradeImportCmd,
Args: cobra.ExactArgs(1),
}
cmd.Flags().StringVar(&upgradeBytesFilePath, upgradeBytesFilePathKey, "", "Import upgrade bytes file into local environment")
return cmd
}
func upgradeImportCmd(_ *cobra.Command, args []string) error {
subnetName := args[0]
if !app.GenesisExists(subnetName) {
ux.Logger.PrintToUser("The provided subnet name %q does not exist", subnetName)
return nil
}
if upgradeBytesFilePath == "" {
var err error
upgradeBytesFilePath, err = app.Prompt.CaptureExistingFilepath("Provide the path to the upgrade file to import")
if err != nil {
return err
}
}
if _, err := os.Stat(upgradeBytesFilePath); err != nil {
if err == os.ErrNotExist {
return fmt.Errorf("the upgrade file specified with path %q does not exist", upgradeBytesFilePath)
}
return err
}
fileBytes, err := os.ReadFile(upgradeBytesFilePath)
if err != nil {
return fmt.Errorf("failed to read the provided upgrade file: %w", err)
}
return app.WriteUpgradeFile(subnetName, fileBytes)
}