Skip to content

Commit

Permalink
feat(cmd/network): Add network set-chain-context subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Oct 11, 2023
1 parent d6313ab commit 4fa9e93
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions cmd/network/set_chain_context.go
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)
},
}

0 comments on commit 4fa9e93

Please sign in to comment.