Permalink
Browse files

Merge pull request #6 from PandaWill/writing_dot_support

Added support for writing .dot files
  • Loading branch information...
2 parents 24c86c7 + 7f139a8 commit 0063341f13a127fab9763c9fbc937d373c12bcf1 @eproxus committed Oct 20, 2015
Showing with 10 additions and 4 deletions.
  1. +10 −4 src/grapherl.erl
View
@@ -215,7 +215,7 @@ uses(From, To) ->
create(Lines, Target, Options) ->
case dot(file(Lines), Target, get_type(Options, Target)) of
- {"", File} ->
+ {ok, File} ->
case proplists:get_value(open, Options) of
undefined -> ok;
Command -> os:cmd(Command ++ " " ++ File), ok
@@ -235,10 +235,16 @@ check_dot() ->
dot(File, Target, Type) ->
TmpFile = string:strip(os:cmd("mktemp -t " ?MODULE_STRING ".XXXX"), both, $\n),
ok = file:write_file(TmpFile, File),
+
TargetName = add_extension(Target, Type),
- Result = os:cmd(io_lib:format("dot -T~p -o~p ~p",
- [Type, TargetName, TmpFile])),
- ok = file:delete(TmpFile),
+ Result = case Type of
+ "dot" -> file:write_file(TargetName, File);
+ _ ->
+ case os:cmd(io_lib:format("dot -T~p -o~p ~p", [Type, TargetName, TmpFile])) of
+ "" -> ok;
+ X -> X
+ end
+ end,
{Result, TargetName}.
add_extension(Target, Type) ->

0 comments on commit 0063341

Please sign in to comment.