diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2015-03-05 11:22:20 -0500 |
---|---|---|
committer | Fred Hebert <mononcqc@ferd.ca> | 2015-03-05 11:22:20 -0500 |
commit | c20e824e631e0e6eca6b9f1ddc869801747b9b41 (patch) | |
tree | 7392f5c7c18b9cf845f63f77a877d49b35396c6e /src | |
parent | 5f773d7adf738a1dbfdb9c047952477007d70ad3 (diff) | |
parent | 1b851267f80b0c0ab839ffb034c9128b796fffc6 (diff) |
Merge pull request #221 from tsloughter/new_template_defaults
New template defaults
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_templater.erl | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl index edfe3bd..588f5b2 100644 --- a/src/rebar_templater.erl +++ b/src/rebar_templater.erl @@ -132,14 +132,41 @@ override_vars([{Var, Default, Doc} | Rest], General) -> %% Default variables, generated dynamically. default_variables() -> + {DefaultAuthor, DefaultEmail} = default_author_and_email(), {{Y,M,D},{H,Min,S}} = calendar:universal_time(), [{date, lists:flatten(io_lib:format("~4..0w-~2..0w-~2..0w",[Y,M,D]))}, {datetime, lists:flatten(io_lib:format("~4..0w-~2..0w-~2..0wT~2..0w:~2..0w:~2..0w+00:00",[Y,M,D,H,Min,S]))}, - {author_name, "Anonymous"}, - {author_email, "anonymous@example.org"}, + {author_name, DefaultAuthor}, + {author_email, DefaultEmail}, {copyright_year, integer_to_list(Y)}, {apps_dir, "apps", "Directory where applications will be created if needed"}]. +default_author_and_email() -> + %% See if we can get a git user and email to use as defaults + case rebar_utils:sh("git config --global user.name", []) of + {ok, Name} -> + case rebar_utils:sh("git config --global user.email", []) of + {ok, Email} -> + {string:strip(Name, both, $\n), string:strip(Email, both, $\n)}; + {error, _} -> + %% Use neither if one doesn't exist + {"Anonymous", "anonymous@example.org"} + end; + {error, _} -> + %% Ok, try mecurial + case rebar_utils:sh("hg showconfig ui.username", []) of + {ok, NameEmail} -> + case re:run(NameEmail, [{capture, [1,2], list}]) of + {match, [Name, Email]} -> + {Name, Email}; + _ -> + {"Anonymous", "anonymous@example.org"} + end; + {error, _} -> + {"Anonymous", "anonymous@example.org"} + end + end. + %% Load variable definitions from the 'Globals' file in the home template %% directory global_variables(State) -> |