Skip to content

Commit

Permalink
feat: update bridge and chain command to use builder pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyasbhat0 committed Dec 1, 2023
1 parent 79a0eff commit be65fea
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cli/cmd/bridge/bridge.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package bridge

import (
"github.com/hugobyte/dive-core/cli/cmd/bridge/relays"
"github.com/hugobyte/dive-core/cli/common"
"github.com/spf13/cobra"
)

var BridgeCmd = common.NewDiveCommandBuilder().
SetUse("bridge").
SetShort("Command for cross chain communication between two different chains").
SetLong(`To connect two different chains using any of the supported cross chain communication protocols.
This will create an relay to connect two different chains and pass any messages between them.`).
SetRun(bridge).
AddCommand(relays.BtpRelayCmd).
AddCommand(relays.IbcRelayCmd).
Build()

func bridge(cmd *cobra.Command, args []string) {}
15 changes: 15 additions & 0 deletions cli/cmd/bridge/relays/btp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package relays

import (
"github.com/hugobyte/dive-core/cli/common"
"github.com/spf13/cobra"
)

var BtpRelayCmd = common.NewDiveCommandBuilder().
SetUse("btp").
SetShort("Starts BTP Relay to bridge between ChainA and ChainB").
SetLong("Setup and Starts BTP Relay between ChainA and ChainB a").
SetRun(btpRelay).
Build()

func btpRelay(cmd *cobra.Command, args []string) {}
1 change: 1 addition & 0 deletions cli/cmd/bridge/relays/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package relays
16 changes: 16 additions & 0 deletions cli/cmd/bridge/relays/ibc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package relays

import (
"github.com/hugobyte/dive-core/cli/common"
"github.com/spf13/cobra"
)

var IbcRelayCmd = common.NewDiveCommandBuilder().
SetUse("ibc").
SetShort("Start connection between Cosmos based chainA and ChainB and initiate communication between them").
SetLong(`This Command deploy , initialize the contracts and make it ready for ibc.
Along with that setup and starts the ibc relayer to establish communication between chains specified`).
SetRun(ibcRelay).
Build()

func ibcRelay(cmd *cobra.Command, args []string) {}
15 changes: 15 additions & 0 deletions cli/cmd/chains/chain/archway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package chain

import (
"github.com/hugobyte/dive-core/cli/common"
"github.com/spf13/cobra"
)

var ArchwayCmd = common.NewDiveCommandBuilder().
SetUse("archway").
SetShort("Build, initialize and start a archway node").
SetLong("The command starts the archway network and allows node in executing contracts").
SetRun(archway).
Build()

func archway(cmd *cobra.Command, args []string) {}
16 changes: 16 additions & 0 deletions cli/cmd/chains/chain/eth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package chain

import (
"github.com/hugobyte/dive-core/cli/common"
"github.com/spf13/cobra"
)

var EthCmd = common.NewDiveCommandBuilder().
SetUse("eth").
SetShort("Build, initialize and start a eth node.").
SetLong(`The command starts an Ethereum node, initiating the process of setting up and launching a local Ethereum network.
It establishes a connection to the Ethereum network and allows the node in executing smart contracts and maintaining the decentralized ledger.`).
SetRun(eth).
Build()

func eth(cmd *cobra.Command, args []string) {}
16 changes: 16 additions & 0 deletions cli/cmd/chains/chain/hardhat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package chain

import (
"github.com/hugobyte/dive-core/cli/common"
"github.com/spf13/cobra"
)

var HardhatCmd = common.NewDiveCommandBuilder().
SetUse("hardhat").
SetShort("Build, initialize and start a hardhat node.").
SetLong(`The command starts an hardhat node, initiating the process of setting up and launching a local hardhat network.
It establishes a connection to the hardhat network and allows the node in executing smart contracts and maintaining the decentralized ledger.`).
SetRun(hardhat).
Build()

func hardhat(cmd *cobra.Command, args []string) {}
16 changes: 16 additions & 0 deletions cli/cmd/chains/chain/icon.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package chain

import (
"github.com/hugobyte/dive-core/cli/common"
"github.com/spf13/cobra"
)

var IconCmd = common.NewDiveCommandBuilder().
SetUse("icon").
SetShort("Build, initialize and start a icon node.").
SetLong(`The command starts an Icon node, initiating the process of setting up and launching a local Icon network.
It establishes a connection to the Icon network and allows the node in executing smart contracts and maintaining the decentralized ledger.`).
SetRun(icon).
Build()

func icon(cmd *cobra.Command, args []string) {}
15 changes: 15 additions & 0 deletions cli/cmd/chains/chain/neutron.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package chain

import (
"github.com/hugobyte/dive-core/cli/common"
"github.com/spf13/cobra"
)

var NeutronCmd = common.NewDiveCommandBuilder().
SetUse("neutron").
SetShort("Build, initialize and start a neutron node").
SetLong("The command starts the neutron network and allows node in executing contracts").
SetRun(neutron).
Build()

func neutron(cmd *cobra.Command, args []string) {}
44 changes: 44 additions & 0 deletions cli/cmd/chains/chains.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package chains

import (
"os"
"slices"

"github.com/hugobyte/dive-core/cli/cmd/chains/chain"
"github.com/hugobyte/dive-core/cli/common"
"github.com/spf13/cobra"
)

var ChainCmd = common.NewDiveCommandBuilder().
SetUse("chain").
SetShort("Build, initialize and start a given blockchain node").
SetLong(`The command builds, initializes, and starts a specified blockchain node, providing a seamless setup process.
It encompasses compiling and configuring the necessary dependencies and components required for the blockchain network.
By executing this command, the node is launched, enabling network participation, transaction processing, and ledger
maintenance within the specified blockchain ecosystem.`,
).
AddCommand(chain.IconCmd).
AddCommand(chain.EthCmd).
AddCommand(chain.HardhatCmd).
AddCommand(chain.ArchwayCmd).
AddCommand(chain.NeutronCmd).
SetRun(chains).
Build()

func chains(cmd *cobra.Command, args []string) {

validArgs := cmd.ValidArgs
for _, c := range cmd.Commands() {
validArgs = append(validArgs, c.Name())
}
cmd.ValidArgs = validArgs

if len(args) == 0 {
cmd.Help()

} else if !slices.Contains(cmd.ValidArgs, args[0]) {

cmd.Usage()
os.Exit(1)
}
}
4 changes: 4 additions & 0 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cmd
import (
"os"

"github.com/hugobyte/dive-core/cli/cmd/bridge"
"github.com/hugobyte/dive-core/cli/cmd/chains"
"github.com/hugobyte/dive-core/cli/cmd/social"
"github.com/hugobyte/dive-core/cli/cmd/utility"
"github.com/hugobyte/dive-core/cli/common"
Expand All @@ -19,6 +21,8 @@ var rootCmd = common.NewDiveCommandBuilder().
AddCommand(utility.VersionCmd).
AddCommand(social.DiscordCmd).
AddCommand(social.TwitterCmd).
AddCommand(chains.ChainCmd).
AddCommand(bridge.BridgeCmd).
AddBoolPersistentFlag(&common.DiveLogs, "verbose", false, "Prints out logs to Stdout").
SetRunE(run).
Build()
Expand Down

0 comments on commit be65fea

Please sign in to comment.