-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cmd/network): Add network set-chain-context subcommand
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package network | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
cliConfig "github.com/oasisprotocol/cli/config" | ||
) | ||
|
||
var setChainContextCmd = &cobra.Command{ | ||
Use: "set-chain-context <name> <chain-context>", | ||
Short: "Sets the chain context of the given network", | ||
Args: cobra.ExactArgs(2), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cfg := cliConfig.Global() | ||
name, chainContext := args[0], args[1] | ||
|
||
net := cfg.Networks.All[name] | ||
if net == nil { | ||
cobra.CheckErr(fmt.Errorf("network '%s' does not exist", name)) | ||
return // To make staticcheck happy as it doesn't know CheckErr exits. | ||
} | ||
|
||
net.ChainContext = chainContext | ||
|
||
err := cfg.Save() | ||
cobra.CheckErr(err) | ||
}, | ||
} |