diff options
author | Eric <[email protected]> | 2012-09-17 12:09:09 -0500 |
---|---|---|
committer | Eric <[email protected]> | 2012-09-18 10:05:12 -0700 |
commit | d98c4fc0a9ecd28dc3ce50c250813736e7fc390a (patch) | |
tree | 0ef0814cf7734349641fe8c7259386951ba35723 | |
parent | 8281dac892b5986e66d33b7ecad27b7a60216c29 (diff) | |
download | relx-d98c4fc0a9ecd28dc3ce50c250813736e7fc390a.tar.gz relx-d98c4fc0a9ecd28dc3ce50c250813736e7fc390a.tar.bz2 relx-d98c4fc0a9ecd28dc3ce50c250813736e7fc390a.zip |
support adding the 'caller' type to the state
This lets us know whether we where called from the command line or the API
-rw-r--r-- | src/rcl_state.erl | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/rcl_state.erl b/src/rcl_state.erl index 298e60d..72b0fc5 100644 --- a/src/rcl_state.erl +++ b/src/rcl_state.erl @@ -42,6 +42,8 @@ get/2, get/3, put/3, + caller/1, + caller/2, format/1, format/2]). @@ -51,6 +53,7 @@ cmd_args/0]). -record(state_t, {log :: rcl_log:t(), + caller :: caller(), output_dir :: file:name(), lib_dirs=[] :: [file:name()], config_files=[] :: [file:filename()], @@ -72,6 +75,7 @@ rcl_release:vsn()}, rcl_release:t()). -type cmd_args() :: proplists:proplist(). +-type caller() :: command_line | api. -opaque t() :: record(state_t). %%============================================================================ @@ -178,17 +182,27 @@ put(M=#state_t{config_values=Config}, Key, Value) when erlang:is_atom(Key) -> M#state_t{config_values=ec_dictionary:add(Key, Value, Config)}. +-spec caller(t()) -> caller(). +caller(#state_t{caller=Caller}) -> + Caller. + +-spec caller(t(), caller()) -> t(). +caller(S, Caller) -> + S#state_t{caller=Caller}. + -spec format(t()) -> iolist(). format(Mod) -> format(Mod, 0). -spec format(t(), non_neg_integer()) -> iolist(). format(#state_t{log=LogState, output_dir=OutDir, lib_dirs=LibDirs, + caller=Caller, config_values=Values0, goals=Goals, config_files=ConfigFiles, - providers=Providers}, + providers=Providers}, Indent) -> + Values1 = ec_dictionary:to_list(Values0), [rcl_util:indent(Indent), - <<"state:\n">>, + <<"state(">>, erlang:atom_to_list(Caller), <<"):\n">>, rcl_util:indent(Indent + 1), <<"log: ">>, rcl_log:format(LogState), <<",\n">>, rcl_util:indent(Indent + 1), "config files: \n", [[rcl_util:indent(Indent + 2), ConfigFile, ",\n"] || ConfigFile <- ConfigFiles], |