Skip to content
This repository has been archived by the owner on Jul 6, 2018. It is now read-only.

Make cli more robust #36

Merged
merged 10 commits into from
Jun 26, 2017
Merged

Make cli more robust #36

merged 10 commits into from
Jun 26, 2017

Conversation

ethanfrey
Copy link
Contributor

This addresses these issues

#35
#19

@ethanfrey ethanfrey mentioned this pull request Jun 26, 2017
commands/init.go Outdated
// make sure there is a directory here in any case
os.MkdirAll(root, dirPerm)

// check there is a config.toml file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// check if there is a config.toml file

commands/init.go Outdated
defer d.Close()

// read to see if any files here...
files, err := d.Readdirnames(5)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment about the argument you are passing in.

commands/init.go Outdated
return false, errors.WithStack(err)
}

// check there are non-empty checkpoints and validators dirs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if

commands/init.go Outdated
// return err
// }
//
// I tried using PersistentPreRun,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to reduce the use of first-person. "This can't just be called during PersistentPreRun because ..."

Also, do we really need an example of calling the function and returning an error ?

return nil
}

doc, err := tcmd.ParseGenesisFile(genesis)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this really be in tendermint/cmd/commands ? Would it serve better in tendermint/types ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can move, tried to do minimal changes in tendermint (i'm scared to touch too much).

If you comment on that issue, I will update this: tendermint/tendermint#561

@@ -22,6 +22,10 @@ data to other peers as needed.
}

func doTxQuery(cmd *cobra.Command, args []string) error {
if err := commands.RequireInit(cmd); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not thrilled that we have to do this with every cmd func. Can we not move it into root command, so it only needs to be called in one place ? Or otherwise have some wrapper convention ? I'm worried new commands will neglect it ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a problem, as some commands (eg. init and keys) do not require Init.

I tried to add it to the query root command via PreRunE, but that didn't work, as you noticed in the comment above. If you have a better idea, I am totally game. It hurts me a bit to copy this all over....

Only other idea was to have a decorator, that takes RunE and returns a RunE with this prefix. But I thought this was too much magic from the python world. but happy to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RunE: RequireInit(runQuery)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my other thought. I'd rather that RequireInit(runQuery) piece than copying this everywhere :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, will update both repos.

test/init.sh Outdated
}

oneTimeTearDown() {
printf "\nstoping tendermint..."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stopping

test/init.sh Outdated
assertFalse "ls ${TMHOME} 2>/dev/null >&2"

# no node where we go
echo y | tmcli init --node=tcp://localhost:9999 --chain-id="bad-chain-id" > /dev/null 2>&1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that it matters here but we should only change one thing at a time. ie. we should use the correct chain-id if we're using the wrong node

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good point

assertFalse "warning on re-init" $?
checkDir $TMHOME 3

# unless we --force-reset
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice

test/init.sh Outdated
@@ -27,7 +27,7 @@ oneTimeSetUp() {
}

oneTimeTearDown() {
printf "\nstoping tendermint..."
printf "\nstoping..."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to indicate that "stopping" is spelled wrong, not that we shouldn't say "tendermint" :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahaha....

@ethanfrey ethanfrey merged commit bf3063d into develop Jun 26, 2017
@ethanfrey ethanfrey deleted the feature/35-cli-cleanup branch June 26, 2017 19:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants