-
Notifications
You must be signed in to change notification settings - Fork 67
/
print.go
44 lines (37 loc) · 1015 Bytes
/
print.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
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package upgradecmd
import (
"bytes"
"encoding/json"
"github.com/ava-labs/avalanche-cli/pkg/ux"
"github.com/spf13/cobra"
)
// avalanche subnet upgrade import
func newUpgradePrintCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "print [subnetName]",
Short: "Print the upgrade.json file content",
Long: `Print the upgrade.json file content`,
RunE: upgradePrintCmd,
Args: cobra.ExactArgs(1),
}
return cmd
}
func upgradePrintCmd(_ *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
}
fileBytes, err := app.ReadUpgradeFile(subnetName)
if err != nil {
return err
}
var prettyJSON bytes.Buffer
if err = json.Indent(&prettyJSON, fileBytes, "", " "); err != nil {
return err
}
ux.Logger.PrintToUser(prettyJSON.String())
return nil
}