Skip to content

Commit

Permalink
fix: remove services json file after dive clean and update verbose fl…
Browse files Browse the repository at this point in the history
…ag (#89)

* fix: remove services json on dive clean and update log

* fix: update verbose flag
  • Loading branch information
shreyasbhat0 authored Aug 2, 2023
1 parent 768bbbb commit 2f9d43b
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cli/commands/chain/types/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ It establishes a connection to the Ethereum network and allows the node in execu
if err != nil {
diveContext.FatalError("Failed To Write To File", err.Error())
}
diveContext.StopSpinner("ETH Node Started. Please find service details in current working directory(dive.json)")
diveContext.StopSpinner("ETH Node Started. Please find service details in current working directory(services.json)")
},
}

Expand Down
2 changes: 1 addition & 1 deletion cli/commands/chain/types/hardhat.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ It establishes a connection to the hardhat network and allows the node in execut
if err != nil {
diveContext.FatalError("Failed To Write To File", err.Error())
}
diveContext.StopSpinner("Hardhat Node Started. Please find service details in current working directory(dive.json)")
diveContext.StopSpinner("Hardhat Node Started. Please find service details in current working directory(services.json)")
},
}

Expand Down
5 changes: 2 additions & 3 deletions cli/commands/chain/types/icon.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
const DefaultIconGenesisFile = "github.com/hugobyte/dive/services/jvm/icon/static-files/config/genesis-icon-0.zip"

var (
id = ""
genesis = ""
serviceName = ""
keystorePath = ""
Expand Down Expand Up @@ -81,7 +80,7 @@ It establishes a connection to the Icon network and allows the node in executing
diveContext.FatalError("Failed To Write To File", err.Error())
}

diveContext.StopSpinner("Icon Node Started. Please find service details in current working directory(dive.json) in current working directory")
diveContext.StopSpinner("Icon Node Started. Please find service details in current working directory(services.json) in current working directory")

} else {

Expand All @@ -93,7 +92,7 @@ It establishes a connection to the Icon network and allows the node in executing
diveContext.FatalError("Failed To Write To File", err.Error())
}

diveContext.StopSpinner("Icon Node Started. Please find service details in current working directory(dive.json)")
diveContext.StopSpinner("Icon Node Started. Please find service details in current working directory(services.json)")
}

},
Expand Down
7 changes: 7 additions & 0 deletions cli/commands/clean/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ func NewCleanCmd(diveContext *common.DiveContext) *cobra.Command {
if err == nil {
os.Remove(diveOutPath)
}
servicesOutPath := fmt.Sprintf("%s/%s", pwd, common.ServiceFilePath)
_, err = os.Stat(servicesOutPath)

if err == nil {
os.Remove(servicesOutPath)
}

enclaveName := diveContext.GetEnclaves()
if enclaveName == "" {
diveContext.Log.SetOutput(os.Stderr)
Expand Down
4 changes: 2 additions & 2 deletions cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

"github.com/hugobyte/dive/styles"
"github.com/spf13/cobra"
)
)

func RootCmd() *cobra.Command {
diveContext := common.NewDiveContext()
Expand All @@ -44,7 +44,7 @@ func RootCmd() *cobra.Command {
rootCmd.AddCommand(twitter.NewtwitterCmd(diveContext))
rootCmd.AddCommand(tutorial.NewTutorialCmd(diveContext))

rootCmd.PersistentFlags().BoolVarP(&common.DiveLogs, "logs", "l", false, "Prints out logs to Stdout")
rootCmd.PersistentFlags().BoolVar(&common.DiveLogs, "verbose", false, "Prints out logs to Stdout")

return rootCmd

Expand Down
1 change: 1 addition & 0 deletions cli/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
DiveDitLogFile = "divelog.log"
DiveErorLogFile = "error.log"
DiveOutFile = "dive.json"
ServiceFilePath = "services.json"
starlarkScript = `
def run(plan, args):
plan.stop_service(name=args["service_name"])
Expand Down
16 changes: 4 additions & 12 deletions cli/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ func (dive *DiveserviceResponse) EncodeToString() (string, error) {

return string(encodedBytes), nil
}
func (dive *DiveserviceResponse) WriteDiveResponse() error {

serialisedData, err := dive.EncodeToString()

if err != nil {
return err
}

return WriteToFile(serialisedData)
}

func OpenFile(URL string) error {
var args []string
Expand Down Expand Up @@ -200,7 +190,9 @@ func WriteToServiceFile(serviceName string, data DiveserviceResponse) error {
return err
}

file, err := os.OpenFile(pwd+"/services.json", os.O_CREATE|os.O_WRONLY, 0644)
serviceFile := fmt.Sprintf("%s/%s", pwd, ServiceFilePath)

file, err := os.OpenFile(serviceFile, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return err
}
Expand Down Expand Up @@ -263,7 +255,7 @@ func ReadServiceJsonFile() (Services, error) {
return nil, err
}

jsonFile, _ := os.ReadFile(pwd + "/services.json")
jsonFile, _ := os.ReadFile(pwd + ServiceFilePath)

if len(jsonFile) == 0 {
return nil, nil
Expand Down

0 comments on commit 2f9d43b

Please sign in to comment.