-module(relsync_cli). -export([ do/3, opts/0 ]). do(Name, Options, _Config) -> Help = proplists:is_defined(help, Options), Ssh = proplists:is_defined(ssh, Options), Erl = proplists:is_defined(erl, Options), case {Help, Ssh, Erl} of {true, _, _} -> getopt:usage(relsync_cli:opts(), Name), erlang:halt(0); {_, true, true} -> io:put_chars(standard_error, ["either erl or ssh should provided\n\n"]), getopt:usage(relsync_cli:opts(), Name), erlang:halt(2); {false, true, _} -> ok = relsync:update_nodes(ssh, Options); {false, _, true} -> target_syncer_sup:start_link(), ok = relsync:setup_local_node(Options), ok = relsync:update_nodes(erl, Options); _ -> io:put_chars(standard_error, ["invalid options\n\n"]), getopt:usage(relsync_cli:opts(), Name), erlang:halt(2) end. -spec opts() -> [getopt:option_spec()]. opts() -> [ %% {Name, ShortOpt, LongOpt, ArgSpec, HelpMsg} {destnode, $d, "destination-node", {string, "node@other"}, "Destination node"}, {destpath, $p, "destination-path", {string, "/srv/erlang"}, "Path to release on the destination (Can be on a read-only filesystem)"}, {destrwpath, $q, "destination-rw-path", {string, ""}, "Path to writable location on the destination (empty if not needed)"}, {localpath, $l, "local-path", {string, "./_rel"}, "Path to local release"}, {hooks, $H, "hooks", string, "Erlang module containing hooks to run on the destination"}, {cookie, $c, "cookie", {string, "cookie"}, "Erlang magic cookie to use"}, {sname, $s, "sname", string, "Short name for the local node"}, {name, $n, "name", string, "Long name for the local node"}, {ssh, $S, "ssh", undefined, "Syncronize release over ssh"}, {port, $P, "port", integer, "ssh port to use"}, {user, $u, "user", string, "ssh username"}, {help, $h, "help", undefined, "Show help usage"} ].