-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Implemented rerun handling logic for roller config init #31
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,43 @@ | ||
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 cleanHomeDir(home string) (bool, error) { | ||
isNotEmpty, err := dirNotEmpty(home) | ||
if err != nil { | ||
return false, err | ||
} | ||
if isNotEmpty { | ||
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 | ||
} | ||
err = os.RemoveAll(home) | ||
if err != 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for me
overwrite
returned fromcleanHomeDir
in unclear. also it seems like if the directory is clean,overwrite
returntrue
which IMO is counter intuitive.