Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process command-line files according to config settings #568

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions src/elvis.erl
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,17 @@ process_options([], Cmds, Config) ->
process_commands(Cmds, Config).

-spec process_commands([string()], elvis_config:configs()) ->ok.
process_commands([rock], Config) ->
case elvis_core:rock(Config) of
{fail, _} -> elvis_utils:erlang_halt(1);
ok -> ok
end;
process_commands([rock | Files], Config) ->
case Files of
[] ->
case elvis_core:rock(Config) of
{fail, _} -> elvis_utils:erlang_halt(1);
ok -> ok
end;
_ ->
lists:map(fun(F) -> rock_one_song(F, Config) end, Files)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we remove rock_one_song/2 entirely, too?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thought i had! Pushed commit with that removed.

Paths = [file_to_path(File) || File <- Files],
NewConfig = elvis_config:resolve_files(Config, Paths),
case elvis_core:rock(NewConfig) of
{fail, _} -> elvis_utils:erlang_halt(1);
ok -> ok
end;
process_commands([help | Cmds], Config) ->
Config = help(Config),
Expand All @@ -170,6 +172,16 @@ process_commands([], _Config) ->
process_commands([_Cmd | _Cmds], _Config) ->
throw(unrecognized_or_unimplemented_command).


file_to_path(File) ->
Path = atom_to_list(File),
Dirname = filename:dirname(Path),
Filename = filename:basename(Path),
case elvis_file:find_files([Dirname], Filename) of
[] -> throw({enoent, Path});
[File0] -> File0
end.

%%% Options

-spec help() -> ok.
Expand Down Expand Up @@ -217,17 +229,6 @@ version() ->
"Elvis Core Version: ~s\n",
io:format(Version, [ElvisShellVsn, ElvisCoreVsn]).

rock_one_song(FileName, Config) ->
F = atom_to_list(FileName),
case elvis_core:rock_this(F, Config) of
{fail, _} ->
case application:get_env(elvis_core, keep_rocking, false) of
false -> elvis_utils:erlang_halt(1);
true -> ok
end;
ok -> ok
end.

-spec default_config() -> elvis_config:configs().
default_config() ->
default_config([ fun() -> elvis_config:from_file(?DEFAULT_CONFIG_PATH) end
Expand Down