-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implemented rerun handling logic for roller config init (#31)
- Loading branch information
1 parent
77efd90
commit 8171c61
Showing
10 changed files
with
161 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package initconfig | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/fatih/color" | ||
) | ||
|
||
func OutputCleanError(err error) { | ||
if err != nil { | ||
defer func() { | ||
if r := recover(); r != nil { | ||
os.Exit(1) | ||
} | ||
}() | ||
color.Red(err.Error()) | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package initconfig | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func addFlags(cmd *cobra.Command) { | ||
cmd.Flags().StringP(FlagNames.HubRPC, "", defaultHubRPC, "Dymension Hub rpc endpoint") | ||
cmd.Flags().StringP(FlagNames.DAEndpoint, "", "", "The data availability light node endpoint. Runs an Arabica Celestia light node if not provided") | ||
cmd.Flags().StringP(FlagNames.RollappBinary, "", "", "The rollapp binary. Should be passed only if you built a custom rollapp") | ||
cmd.Flags().Uint64P(FlagNames.Decimals, "", 18, "The number of decimal places a rollapp token supports") | ||
cmd.Flags().StringP(FlagNames.Home, "", getRollerRootDir(), "The directory of the roller config files") | ||
} | ||
|
||
func getDecimals(cmd *cobra.Command) uint64 { | ||
decimals, err := cmd.Flags().GetUint64(FlagNames.Decimals) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return decimals | ||
} | ||
|
||
func getRollappBinaryPath(cmd *cobra.Command) string { | ||
rollappBinaryPath := cmd.Flag(FlagNames.RollappBinary).Value.String() | ||
if rollappBinaryPath == "" { | ||
return defaultRollappBinaryPath | ||
} | ||
return rollappBinaryPath | ||
} | ||
|
||
func getInitConfig(cmd *cobra.Command, args []string) InitConfig { | ||
rollappId := args[0] | ||
denom := args[1] | ||
home := cmd.Flag(FlagNames.Home).Value.String() | ||
createLightNode := !cmd.Flags().Changed(FlagNames.DAEndpoint) | ||
rollappBinaryPath := getRollappBinaryPath(cmd) | ||
decimals := getDecimals(cmd) | ||
return InitConfig{ | ||
Home: home, | ||
RollappID: rollappId, | ||
RollappBinary: rollappBinaryPath, | ||
CreateDALightNode: createLightNode, | ||
Denom: denom, | ||
HubID: DefaultHubID, | ||
Decimals: decimals, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package initconfig | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/manifoldco/promptui" | ||
) | ||
|
||
func dirNotEmpty(path string) (bool, error) { | ||
info, err := os.Stat(path) | ||
if err != nil || !info.IsDir() { | ||
return false, err | ||
} | ||
files, err := ioutil.ReadDir(path) | ||
return len(files) > 0, err | ||
} | ||
|
||
func promptOverwriteConfig(home string) (bool, error) { | ||
prompt := promptui.Prompt{ | ||
Label: fmt.Sprintf("Directory %s is not empty. Do you want to overwrite", home), | ||
IsConfirm: true, | ||
} | ||
_, err := prompt.Run() | ||
if err != nil { | ||
if err == promptui.ErrAbort { | ||
return false, nil | ||
} | ||
return false, err | ||
} | ||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters