diff --git a/cmd/network/network.go b/cmd/network/network.go index dae4b2b9..fd429420 100644 --- a/cmd/network/network.go +++ b/cmd/network/network.go @@ -55,6 +55,7 @@ func init() { Cmd.AddCommand(governance.Cmd) Cmd.AddCommand(listCmd) Cmd.AddCommand(rmCmd) + Cmd.AddCommand(setChainContextCmd) Cmd.AddCommand(setDefaultCmd) Cmd.AddCommand(setRPCCmd) Cmd.AddCommand(showCmd) diff --git a/cmd/network/set_chain_context.go b/cmd/network/set_chain_context.go new file mode 100644 index 00000000..78582aa7 --- /dev/null +++ b/cmd/network/set_chain_context.go @@ -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 ", + 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) + }, +}