Merge pull request #372 from robertoaloi/eval

Implement eval command via nodetool
This commit is contained in:
Fred Hebert 2014-10-21 08:56:41 -04:00
commit 71aedb8674
5 changed files with 69 additions and 4 deletions

1
THANKS
View file

@ -127,3 +127,4 @@ alisdair sullivan
Alexander Verbitsky
Andras Horvath
Drew Varner
Roberto Aloi

View file

@ -95,9 +95,23 @@ main(Args) ->
Other ->
io:format("~p\n", [Other])
end;
["eval", Str0] ->
Str = string:strip(Str0, right, $.) ++ ".",
Bindings = erl_eval:new_bindings(),
case rpc:call(TargetNode,
erl_eval,
exprs,
[parse(Str), Bindings],
60000) of
{badrpc, Reason} ->
io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]),
halt(1);
{value, Value, _Bindings} ->
io:format("~p\n", [Value])
end;
Other ->
io:format("Other: ~p\n", [Other]),
io:format("Usage: nodetool {chkconfig|getpid|ping|stop|restart|reboot|rpc|rpc_infinity|rpcterms}\n")
io:format("Usage: nodetool {chkconfig|getpid|ping|stop|restart|reboot|rpc|rpc_infinity|rpcterms|eval}\n")
end,
net_kernel:stop().
@ -180,3 +194,8 @@ consult(Cont, Str, Acc) ->
{more, Cont1} ->
consult(Cont1, eof, Acc)
end.
parse(Str) ->
{ok, Tokens, _} = erl_scan:string(Str),
{ok, Exprs} = erl_parse:parse_exprs(Tokens),
Exprs.

View file

@ -293,6 +293,19 @@ case "$1" in
exec $ERTS_PATH/to_erl $PIPE_DIR
;;
eval)
# Make sure a node IS running
ping_node > /dev/null 2>&1
ES=$?
if [ "$ES" -ne 0 ]; then
echo "Node is not running!"
exit $ES
fi
shift
$NODETOOL eval "$1"
;;
remote_console)
# Make sure a node is running
ping_node
@ -396,7 +409,7 @@ case "$1" in
echo $PID
;;
*)
echo "Usage: $SCRIPT {start|start_boot <file>|foreground|stop|restart|reboot|ping|console|getpid|console_clean|console_boot <file>|attach|remote_console|upgrade}"
echo "Usage: $SCRIPT {start|start_boot <file>|foreground|stop|restart|reboot|ping|console|getpid|console_clean|console_boot <file>|attach|eval|remote_console|upgrade}"
exit 1
;;
esac

View file

@ -234,6 +234,19 @@ case "$1" in
exec $ERTS_PATH/to_erl $PIPE_DIR
;;
eval)
# Make sure a node IS running
ping_node > /dev/null 2>&1
ES=$?
if [ "$ES" -ne 0 ]; then
echo "Node is not running!"
exit $ES
fi
shift
$NODETOOL eval "$1"
;;
remote_console)
# Make sure a node is running
ping_node
@ -339,7 +352,7 @@ case "$1" in
echo $PID
;;
*)
echo "Usage: $SCRIPT {start|start_boot <file>|foreground|stop|restart|reboot|ping|console|getpid|console_clean|console_boot <file>|attach|remote_console|upgrade}"
echo "Usage: $SCRIPT {start|start_boot <file>|foreground|stop|restart|reboot|ping|console|getpid|console_clean|console_boot <file>|attach|eval|remote_console|upgrade}"
exit 1
;;
esac

View file

@ -95,9 +95,23 @@ main(Args) ->
Other ->
io:format("~p\n", [Other])
end;
["eval", Str0] ->
Str = string:strip(Str0, right, $.) ++ ".",
Bindings = erl_eval:new_bindings(),
case rpc:call(TargetNode,
erl_eval,
exprs,
[parse(Str), Bindings],
60000) of
{badrpc, Reason} ->
io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]),
halt(1);
{value, Value, _Bindings} ->
io:format("~p\n", [Value])
end;
Other ->
io:format("Other: ~p\n", [Other]),
io:format("Usage: nodetool {chkconfig|getpid|ping|stop|restart|reboot|rpc|rpc_infinity|rpcterms}\n")
io:format("Usage: nodetool {chkconfig|getpid|ping|stop|restart|reboot|rpc|rpc_infinity|rpcterms|eval}\n")
end,
net_kernel:stop().
@ -180,3 +194,8 @@ consult(Cont, Str, Acc) ->
{more, Cont1} ->
consult(Cont1, eof, Acc)
end.
parse(Str) ->
{ok, Tokens, _} = erl_scan:string(Str),
{ok, Exprs} = erl_parse:parse_exprs(Tokens),
Exprs.