diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2015-05-30 14:50:09 +0000 |
---|---|---|
committer | Fred Hebert <mononcqc@ferd.ca> | 2015-05-30 14:50:09 +0000 |
commit | c87f2a2c73ccdff29c0b320070c5599716b47fca (patch) | |
tree | 34c8a06857484d4e269290fa10064005a29c288a | |
parent | 30847ec66103bdbaa8b7787577677c24d583500f (diff) |
Optionally allow node names to the rebar3 shell.
Helps with integration efforts, but unfortunately can't support the
'-sname' and '-name' options, only '--sname' and '--name'.
-rw-r--r-- | src/rebar_prv_shell.erl | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/src/rebar_prv_shell.erl b/src/rebar_prv_shell.erl index 5110f52..c80badf 100644 --- a/src/rebar_prv_shell.erl +++ b/src/rebar_prv_shell.erl @@ -57,7 +57,11 @@ init(State) -> {desc, info()}, {opts, [{config, undefined, "config", string, "Path to the config file to use. Defaults to the " - "sys_config defined for relx, if present."}]} + "sys_config defined for relx, if present."}, + {name, undefined, "name", atom, + "Gives a long name to the node."}, + {sname, undefined, "sname", atom, + "Gives a short name to the node."}]} ]) ), {ok, State1}. @@ -79,6 +83,7 @@ format_error(Reason) -> %% immediately kill the script. ctrl-g, however, works fine shell(State) -> + setup_name(State), setup_paths(State), maybe_boot_apps(State), setup_shell(), @@ -117,17 +122,6 @@ setup_paths(State) -> %% add project app test paths ok = add_test_paths(State). -reread_config(State) -> - case find_config(State) of - no_config -> - ok; - ConfigList -> - _ = [application:set_env(Application, Key, Val) - || {Application, Items} <- ConfigList, - {Key, Val} <- Items], - ok - end. - maybe_boot_apps(State) -> case find_apps_to_boot(State) of undefined -> @@ -140,6 +134,19 @@ maybe_boot_apps(State) -> boot_apps(Apps) end. +setup_name(State) -> + {Opts, _} = rebar_state:command_parsed_args(State), + case {proplists:get_value(name, Opts), proplists:get_value(sname, Opts)} of + {undefined, undefined} -> + ok; + {Name, undefined} -> + net_kernel:start([Name, longnames]); + {undefined, SName} -> + net_kernel:start([SName, shortnames]); + {_, _} -> + ?ABORT("Cannot have both short and long node names defined", []) + end. + find_apps_to_boot(State) -> %% Try the shell_apps option case rebar_state:get(State, shell_apps, undefined) of @@ -164,6 +171,17 @@ load_apps(Apps) -> not lists:keymember(App, 1, application:loaded_applications())], ok. +reread_config(State) -> + case find_config(State) of + no_config -> + ok; + ConfigList -> + _ = [application:set_env(Application, Key, Val) + || {Application, Items} <- ConfigList, + {Key, Val} <- Items], + ok + end. + boot_apps(Apps) -> ?WARN("The rebar3 shell is a development tool; to deploy " "applications in production, consider using releases " |