-
Notifications
You must be signed in to change notification settings - Fork 212
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
WIP Repl commands #144
WIP Repl commands #144
Conversation
@y0sher please, take a look at this new PR. |
hi please |
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.
Please see my comments, I'm changing title to WIP.
ENV
Outdated
@@ -0,0 +1,2 @@ | |||
DataPath= | |||
NetworkID= |
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 meant these should be exposed to the repl from the node's config. they are already presented there
p2p/localnode.go
Outdated
SetVariables(params, flags []string) error | ||
Restart(params, flags []string) error | ||
NeedRestartNode(params, flags []string) bool | ||
Setup(allocation string) 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.
I'd rather you create an interface inside repl that has these methods and then in the future we could use LocalNode as this interface if we implement them.
p2p/localnodeimpl.go
Outdated
// Setup setup POST. | ||
func (n *localNodeImp) Setup(allocation string) error { | ||
return nil | ||
} |
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.
As I said above, please take these out. you can name it a REPLClient
interface
repl/variables.go
Outdated
} | ||
|
||
func echo(key string) { | ||
fmt.Println(os.Getenv(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.
You should implement normal echo that replaces ENV variables with the stored env key.
repl/variables.go
Outdated
"strings" | ||
) | ||
|
||
func setVariables(path string) 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.
Instead of reading from a file the node (or interface that will represent a node in the future) should expose a function that return the variables that are exported and their values.
repl/repl.go
Outdated
} | ||
|
||
// StartRepl starts REPL. | ||
func StartRepl(node p2p.LocalNode, envPath string) { |
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.
Replace node
with an interface that holds the needed functions and that LocalNode can implement.
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.
Good job, please check my comments.
repl/repl.go
Outdated
if err != nil { | ||
r.node.Debug(err.Error()) | ||
log.Debug(err.Error()) | ||
} else { |
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.
In go a good pattern is,
if err != nil {
log.Error(err)
retutn
}
r.setup()
Instead of using if/else just return inside the error condition
repl/repl.go
Outdated
err := r.client.Unlock(passphrase) | ||
if err != nil { | ||
log.Debug(err.Error()) | ||
} else { |
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 , in idomatic go
if err != nil {
log.Debug(err)
return
}
// The code that was on the else
Note: this command refers to rest of the places you do the same.
Please check https://golang.org/doc/effective_go.html#errors
repl/variables.go
Outdated
|
||
func setVariables(values map[string]string) error { | ||
for key, value := range values { | ||
err := os.Setenv(key, value) |
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.
By environment variables we meant variables contained inside the node running and not the OS level. This might be problematic if one runs more than one node on a machine and the variables clash
repl/variables.go
Outdated
value = strings.TrimSpace(fields[1]) | ||
} | ||
|
||
err := os.Setenv(key, value) |
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.
Setting variables shouldn't happen from the echo command. Instead you should create a function that translate variables to their values (recognize variables starting with $
. Then every command could use ENV variables.
Setting a variable should be another command (set
/export
) and should be contained inside the node software.
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.
sorry if this is a silly question but what is ENV variable?
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.
Environment variables are variables variables KEY/VALUE pairs that are exposed widely in operating systems so software can read and use them.
We want to simulate this feature inside the spacemesh node without affecting the actual operating system environment variables.
The repl should be able read such variables from the node. (As NetworkID and DataFilePath for example)
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.
so let's see if I understood right. All that I have to do is get the variables that the user puts on console (e.g. $NetworkID), ask the node the variable and print the value on the console, right? there is no need for a method like setVariables
like I created.
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 now you can start with this. in the future we might want to enable users to set variables through the console aswell.
@y0sher, should I do any change or is it ok now? |
Great job @lucasalcantara , please write unit tests before we can merge it. |
@y0sher I don't know if I can add unit test for it. Since the lib doesn't return the messages that it receives. So, if you have any idea how I can do it I will be glad of try. |
Closed due to inactivity |
Thanks for contributing this code! we are about to use it as our first CLI wallet! |
Merged opied code int CLIWallet project |
Related issue #122
What has been done
Commands added