From d98c4fc0a9ecd28dc3ce50c250813736e7fc390a Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 17 Sep 2012 12:09:09 -0500 Subject: support adding the 'caller' type to the state This lets us know whether we where called from the command line or the API --- src/rcl_state.erl | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/rcl_state.erl') 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], -- cgit v1.2.3