-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Update to Cobra CLI #64
Conversation
Modified init to be more robust when an existing validator key is there but no genesis file. Also, do we really want to print "%+v" for the error all the time. For debugging, the stack trace can be nice, but when using it and I type in an empty account, I just want the message, not the stack dump. Maybe a separate flag "--verbose" / "--debug" so it will print this info, and just "%v" otherwise? You would just have to extract this idiom: |
hmm okay, yeah I agree that it would be nice to not have the stack dump when we're not debugging... Even easier just reference a string variable that can be either |
How about a new function in the func dieOnError(err error) {
if err != nil {
form := "%v"
if viper.GetBool("debug") {
form = "%+v"
}
cmn.Exit(fmt.Sprintf(form, err))
}
} Note the first check, so it does nothing if err is nil, and you can safely call it without checking.. err := foo()
dieOnError(err) |
You do use viper? Or not? Otherwise change the |
Okay cool. Yeah viper is not used yet. Going to update tendermint and basecoin to use viper this week. @ebuchman and I have had a few discussions on using functions to check errors as opposed to checking them in place, the resolution is that we've decided to check errors in place to maintain portability... However I wonder if there is a way to do both... such as check the error in place first, but also if the debug flag is on, do a stack trace print and exit, an alternative util function might look something like this (which would be called after checking for the error in place) func debug(err error) {
if viper.GetBool("debug") && err != nil {
cmn.Exit(fmt.Sprintf(%+v, err))
}
} |
Let @ebuchman decide and please write the prefered mechanism in the style-guide |
@ethanfrey Okay sounds good |
4cdf57a
to
318ce68
Compare
318ce68
to
1b1e35a
Compare
|
c6f118e
to
774d1f9
Compare
@ebuchman |
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.
Great work!
// register flags | ||
registerFlags := []Flag2Register{ | ||
{&ibcChainIDFlag, "ibc_chain_id", "", "ChainID for the new blockchain"}, | ||
{&ibcGenesisFlag, "genesis", "", "Genesis file for the new blockchain"}, |
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.
maybe for consistency all these flags should have ibc_
. that could also avoid breaking changes 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.
actually leave this for now and we can discuss as a team after some QA testing. fine to have this on develop before a final decision
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.
leaving for now
cmd/commands/init.go
Outdated
} | ||
) | ||
|
||
// setupFile aborts on error... or should we return it?? |
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.
looks like it always returns now
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.
removed
cmd/commands/init.go
Outdated
// returns 1 iff it set a file, otherwise 0 (so we can add them) | ||
func setupFile(path, data string, perm os.FileMode) (int, error) { | ||
_, err := os.Stat(path) | ||
if !os.IsNotExist(err) { |
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.
shouldnt this just be os.IsExist
?
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.
causes a permission denied error if we use os.IsExist
, this check is the same as in tendermint core, leaving (will add a comment)
cmd/commands/key.go
Outdated
key := genKey() | ||
keyJSON, err := json.MarshalIndent(key, "", "\t") | ||
fmt.Println(&key) |
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.
remove
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.
done
cmd/commands/query.go
Outdated
if err != nil { | ||
return errors.New(cmn.Fmt("Proof (%v) is invalid hex: %v", c.String("proof"), err)) | ||
} | ||
proofBytes, err := hex.DecodeString(StripHex(proofFlag)) |
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.
check this error
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.
whoops. done
cmd/commands/tx.go
Outdated
{&amountFlag, "amount", "", "Coins to send in transaction of the format <amt><coin>,<amt2><coin2>,... (eg: 1btc,2gold,5silver},"}, | ||
{&gasFlag, "gas", 0, "The amount of gas for the transaction"}, | ||
{&feeFlag, "fee", "", "Coins for the transaction fee of the format <amt><coin>"}, | ||
{&seqFlag, "sequence", -1, "Sequence number for the account (-1 to autocalculate},"}, |
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.
again, } should be )
cmd/commands/utils.go
Outdated
@@ -21,16 +23,87 @@ import ( | |||
tmtypes "github.com/tendermint/tendermint/types" | |||
) | |||
|
|||
//This variable can be overwritten by plugin applications | |||
// if they require a different working directory | |||
var DefaultHome = "basecoin" |
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.
.basecoin
cmd/commands/utils.go
Outdated
func BasecoinRoot(rootDir string) string { | ||
if rootDir == "" { | ||
rootDir = os.Getenv("BCHOME") | ||
} | ||
if rootDir == "" { | ||
rootDir = os.Getenv("HOME") + "/.basecoin" | ||
rootDir = os.Getenv("HOME") + "/." + DefaultHome |
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.
path.Join(os.Getenv("HOME"), DefaultHome)
cmd/commands/utils.go
Outdated
var debug bool | ||
RootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "enables stack trace error messages") | ||
|
||
//note that Execute() prints the error if encountered, so no need to reprint the error, |
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.
This is bad, because it also prints the help menu, which may be totally irrelevant.
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.
solved with cmd.SilenceUsage but update the comment.
cmd/commands/utils.go
Outdated
} | ||
} | ||
|
||
type Flag2Register struct { |
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.
neat. a comment would be helpful
cmd/commands/init.go
Outdated
// returns 1 iff it set a file, otherwise 0 (so we can add them) | ||
func setupFile(path, data string, perm os.FileMode) (int, error) { | ||
_, err := os.Stat(path) | ||
if !os.IsNotExist(err) { | ||
if !os.IsNotExist(err) { //permission errors generated if use os.IsExist |
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.
Investigate
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.
See this gist for a pretty informative description as to what is going on, looks like os.IsExist is not appropriate here https://gist.github.com/mastef/05f46d3ab2f5ed6a6787#file-isexist_vs_isnotexist-go-L35-L43
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.
I think we can just check the err == nil
. But fine.
cmd/commands/query.go
Outdated
@@ -198,6 +198,9 @@ func verifyCmd(cmd *cobra.Command, args []string) error { | |||
} | |||
|
|||
proofBytes, err := hex.DecodeString(StripHex(proofFlag)) | |||
if err != nil { | |||
return errors.Errorf("Proof (%v) is invalid hex: %v\n", proofBytes, err) |
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.
should be proofFlag here, the bytes will be nil if there's an err
cmd/commands/utils.go
Outdated
@@ -25,14 +26,14 @@ import ( | |||
|
|||
//This variable can be overwritten by plugin applications | |||
// if they require a different working directory | |||
var DefaultHome = "basecoin" | |||
var DefaultHome = ".basecoin" |
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.
actually we should probably just put the whole path here
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.
This variable exists because it is changed by each basecoin plugin which may require a modified genesis (and the original space should not be overwritten). Only if we choose not to enforce use of the home directory for default basecoin-plugin working spaces should be we change this. If we choose to enforce using the home directory (which I had assumed we would) then it does not make sense to modify this to include the full path as it would mean that each plugin would be duplicating the code os.Getenv("Home")
.. Just considering
I'll handle my comments and the rebase tmrw. |
Okay made minor fixes/left rebase and decision/code changes on your issues based on my comment - to you |
rebaseFixes int removed ExitOnErr int int int int int added uint64 to RegisterFlags
int int int int
Merge sdk2 into develop
Closes #62, Closes #61, Closes #46
In conjunction with Basecoin-Examples PR tendermint/basecoin-examples#8
Updated CLI, new "simplified" basecoin, and all associated documentation/tutorials