mirror of
https://github.com/correl/rebar.git
synced 2024-11-27 11:09:55 +00:00
Merge pull request #372 from robertoaloi/eval
Implement eval command via nodetool
This commit is contained in:
commit
71aedb8674
5 changed files with 69 additions and 4 deletions
1
THANKS
1
THANKS
|
@ -127,3 +127,4 @@ alisdair sullivan
|
||||||
Alexander Verbitsky
|
Alexander Verbitsky
|
||||||
Andras Horvath
|
Andras Horvath
|
||||||
Drew Varner
|
Drew Varner
|
||||||
|
Roberto Aloi
|
|
@ -95,9 +95,23 @@ main(Args) ->
|
||||||
Other ->
|
Other ->
|
||||||
io:format("~p\n", [Other])
|
io:format("~p\n", [Other])
|
||||||
end;
|
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 ->
|
Other ->
|
||||||
io:format("Other: ~p\n", [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,
|
end,
|
||||||
net_kernel:stop().
|
net_kernel:stop().
|
||||||
|
|
||||||
|
@ -180,3 +194,8 @@ consult(Cont, Str, Acc) ->
|
||||||
{more, Cont1} ->
|
{more, Cont1} ->
|
||||||
consult(Cont1, eof, Acc)
|
consult(Cont1, eof, Acc)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
parse(Str) ->
|
||||||
|
{ok, Tokens, _} = erl_scan:string(Str),
|
||||||
|
{ok, Exprs} = erl_parse:parse_exprs(Tokens),
|
||||||
|
Exprs.
|
||||||
|
|
|
@ -293,6 +293,19 @@ case "$1" in
|
||||||
exec $ERTS_PATH/to_erl $PIPE_DIR
|
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)
|
remote_console)
|
||||||
# Make sure a node is running
|
# Make sure a node is running
|
||||||
ping_node
|
ping_node
|
||||||
|
@ -396,7 +409,7 @@ case "$1" in
|
||||||
echo $PID
|
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
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -234,6 +234,19 @@ case "$1" in
|
||||||
exec $ERTS_PATH/to_erl $PIPE_DIR
|
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)
|
remote_console)
|
||||||
# Make sure a node is running
|
# Make sure a node is running
|
||||||
ping_node
|
ping_node
|
||||||
|
@ -339,7 +352,7 @@ case "$1" in
|
||||||
echo $PID
|
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
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -95,9 +95,23 @@ main(Args) ->
|
||||||
Other ->
|
Other ->
|
||||||
io:format("~p\n", [Other])
|
io:format("~p\n", [Other])
|
||||||
end;
|
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 ->
|
Other ->
|
||||||
io:format("Other: ~p\n", [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,
|
end,
|
||||||
net_kernel:stop().
|
net_kernel:stop().
|
||||||
|
|
||||||
|
@ -180,3 +194,8 @@ consult(Cont, Str, Acc) ->
|
||||||
{more, Cont1} ->
|
{more, Cont1} ->
|
||||||
consult(Cont1, eof, Acc)
|
consult(Cont1, eof, Acc)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
parse(Str) ->
|
||||||
|
{ok, Tokens, _} = erl_scan:string(Str),
|
||||||
|
{ok, Exprs} = erl_parse:parse_exprs(Tokens),
|
||||||
|
Exprs.
|
||||||
|
|
Loading…
Reference in a new issue