Skip to content

Commit

Permalink
fix: bug fixes for dive cli (#45)
Browse files Browse the repository at this point in the history
* fix: mutliple argument issue

* fix: logs

* fix: update logging

* fix: throw error on invalid chain
  • Loading branch information
shreyasbhat0 authored Jul 19, 2023
1 parent 6efdf3f commit 9212be0
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 35 deletions.
17 changes: 16 additions & 1 deletion cli/commands/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,26 @@ func btpBridgeCmd(diveContext *common.DiveContext) *cobra.Command {
Short: "Starts Bridge BTP between ChainA and Chain B",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 0 {
diveContext.FatalError("Invalid Usage of command. Find cmd", cmd.UsageString())

}

enclaveCtx, err := diveContext.GetEnclaveContext()

if err != nil {
logrus.Errorln(err)
}
diveContext.StartSpinner(fmt.Sprintf(" Starting BTP Bridge for %s,%s", chainA, chainB))

bridge, _ := cmd.Flags().GetBool("bridge")

params := fmt.Sprintf(`{"args":{"links": {"src": "%s", "dst": "%s"},"bridge":"%s"}}`, chainA, chainB, strconv.FormatBool(bridge))

if strings.ToLower(chainA) == "icon" && strings.ToLower(chainB) == "icon" {

diveContext.SetSpinnerMessage("Executing BTP Starlark Package")

data, _, err := enclaveCtx.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveBridgeScript, bridgeMainFunction, params, common.DiveDryRun, common.DiveDefaultParallelism, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{})

if err != nil {
Expand All @@ -65,7 +72,10 @@ func btpBridgeCmd(diveContext *common.DiveContext) *cobra.Command {
response := diveContext.GetSerializedData(data)

common.WriteToFile(response)
} else {

diveContext.SetSpinnerMessage(fmt.Sprintf("BTP Bridge Setup Completed between %s and %s", chainA, chainB))
} else if strings.ToLower(chainA) == "icon" && (strings.ToLower(chainB) == "eth" || strings.ToLower(chainB) == "hardhat") {
diveContext.SetSpinnerMessage("Executing BTP Starlark Package")
data, _, err := enclaveCtx.RunStarlarkRemotePackage(diveContext.Ctx, common.DiveRemotePackagePath, common.DiveBridgeScript, bridgeMainFunction, params, common.DiveDryRun, common.DiveDefaultParallelism, []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag{})

if err != nil {
Expand All @@ -74,7 +84,12 @@ func btpBridgeCmd(diveContext *common.DiveContext) *cobra.Command {
response := diveContext.GetSerializedData(data)

common.WriteToFile(response)
diveContext.SetSpinnerMessage(fmt.Sprintf("BTP Bridge Setup Completed between %s and %s", chainA, chainB))
} else {
diveContext.FatalError("Chains Not Supported", "Supported Chains [icon,eth,hardhat]")
}

diveContext.StopSpinner(" Execution Completed")
},
}

Expand Down
7 changes: 6 additions & 1 deletion cli/commands/chain/types/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ func NewEthCmd(diveContext *common.DiveContext) *cobra.Command {
network and allows the node in executing smart contracts and maintaining the decentralized ledger.`,
Run: func(cmd *cobra.Command, args []string) {

if len(args) != 0 {
diveContext.FatalError("Invalid Usage of command. Find cmd", cmd.UsageString())

}

data, err := RunEthNode(diveContext)

if err != nil {
Expand All @@ -25,7 +30,7 @@ network and allows the node in executing smart contracts and maintaining the dec
if err != nil {
diveContext.FatalError("Failed To Write To File", err.Error())
}
diveContext.StopSpinner("Hardhat Node Started")
diveContext.StopSpinner("ETH Node Started")
},
}

Expand Down
5 changes: 5 additions & 0 deletions cli/commands/chain/types/hardhat.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ func NewHardhatCmd(diveContext *common.DiveContext) *cobra.Command {
network and allows the node in executing smart contracts and maintaining the decentralized ledger.`,
Run: func(cmd *cobra.Command, args []string) {

if len(args) != 0 {
diveContext.FatalError("Invalid Usage of command. Find cmd", cmd.UsageString())

}

data, err := RunHardhatNode(diveContext)

if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion cli/commands/chain/types/icon.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ func NewIconCmd(diveContext *common.DiveContext) *cobra.Command {
network and allows the node in executing smart contracts and maintaining the decentralized ledger.`,
Run: func(cmd *cobra.Command, args []string) {

if len(args) != 0 {
diveContext.FatalError("Invalid Usage of command. Find cmd", cmd.UsageString())

}

decentralisation, _ := cmd.Flags().GetBool("decentralisation")

serviceConfig := &IconServiceConfig{}
Expand All @@ -96,6 +101,7 @@ network and allows the node in executing smart contracts and maintaining the dec

nodeResponse, err := RunIconNode(diveContext, serviceConfig, genesis)
if err != nil {
diveContext.StopSpinner("Failed")
diveContext.FatalError("Run Icon Node Failed", err.Error())
}

Expand Down Expand Up @@ -211,7 +217,7 @@ func RunIconNode(diveContext *common.DiveContext, serviceConfig *IconServiceConf
if genesisFilePath != "" {
genesisFileName := filepath.Base(genesisFilePath)
r, d, err := kurtosisEnclaveContext.UploadFiles(genesisFilePath, genesisFileName)
logrus.Infof("File Uploaded sucessfully : UUID %s", r)
diveContext.SetSpinnerMessage(fmt.Sprintf("File Uploaded sucessfully : UUID %s", r))
uploadedFiles = fmt.Sprintf(`{"file_path":"%s","file_name":"%s"}`, d, genesisFileName)

if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ var rootCmd = &cobra.Command{
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {

// latestVersion := common.GetLatestVersion()
// if common.DiveVersion != latestVersion {
// logrus.Warnf("Update available '%s'. Get the latest version of our DIVE CLI for bug fixes, performance improvements, and new features.", latestVersion)
// }
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
Expand Down
66 changes: 38 additions & 28 deletions cli/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"os"
"os/exec"
"runtime"
"strings"
"time"

"github.com/briandowns/spinner"
"github.com/fatih/color"
"github.com/google/go-github/github"
"github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings"
"github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves"
Expand Down Expand Up @@ -56,31 +58,6 @@ func (dive *DiveserviceResponse) WriteDiveResponse(diveContext *DiveContext) err
return WriteToFile(serialisedData)
}

func (diveContext *DiveContext) GetSerializedData(response chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine) string {

var serializedOutputObj string

for executionResponseLine := range response {

runFinishedEvent := executionResponseLine.GetRunFinishedEvent()

if runFinishedEvent == nil {
diveContext.spinner.Color("blue")
diveContext.spinner.Suffix = " Execution in Progress"
} else {

if runFinishedEvent.GetIsRunSuccessful() {
serializedOutputObj = runFinishedEvent.GetSerializedOutput()
} else {
logrus.Fatal("Starlark run Fails")
}
}
}

return serializedOutputObj

}

func OpenFile(URL string) error {
var args []string
switch runtime.GOOS {
Expand Down Expand Up @@ -244,9 +221,42 @@ func (diveContext *DiveContext) SetSpinnerMessage(message string) {
}

func (diveContext *DiveContext) StopSpinner(message string) {

diveContext.spinner.Color("bgCyan")
diveContext.spinner.FinalMSG = fmt.Sprintln(message)
c := color.New(color.FgCyan).Add(color.Underline)
diveContext.spinner.FinalMSG = c.Sprintln(message)
diveContext.spinner.Stop()

}

func (diveContext *DiveContext) GetSerializedData(response chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine) string {

var serializedOutputObj string

for executionResponseLine := range response {

runFinishedEvent := executionResponseLine.GetRunFinishedEvent()

if runFinishedEvent == nil {

diveContext.spinner.Color("blue")
if executionResponseLine.GetProgressInfo() != nil {
c := color.New(color.FgGreen)

diveContext.spinner.Suffix = c.Sprintf(strings.ReplaceAll(executionResponseLine.GetProgressInfo().String(), "current_step_info:", " "))

}
} else {

if runFinishedEvent.GetIsRunSuccessful() {

serializedOutputObj = runFinishedEvent.GetSerializedOutput()

} else {
diveContext.spinner.Stop()
diveContext.log.Fatalln("Starlark Run Failed", executionResponseLine.GetInstructionResult())
}
}
}

return serializedOutputObj

}
Binary file added cli/dive
Binary file not shown.
10 changes: 10 additions & 0 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ package main

import (
"github.com/hugobyte/dive/commands"
"github.com/hugobyte/dive/common"
"github.com/sirupsen/logrus"
)

func main() {

logrus.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05",
})
latestVersion := common.GetLatestVersion()
if common.DiveVersion != latestVersion {
logrus.Warnf("Update available '%s'. Get the latest version of our DIVE CLI for bug fixes, performance improvements, and new features.", latestVersion)
}
commands.Execute()

}

0 comments on commit 9212be0

Please sign in to comment.