Skip to content

Commit 4527c1e

Browse files
author
Michael Klishin
committed
Make Mix CLI support --help, -h and -help, fixes #843
1 parent 5557e62 commit 4527c1e

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

lib/mix/lib/mix/cli.ex

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,11 @@ defmodule Mix.CLI do
55
Runs Mix according to the command line arguments.
66
"""
77
def run(args // System.argv) do
8-
Mix.Local.append_tasks
9-
10-
args = load_mixfile(args)
11-
{ task, args } = get_task(args)
12-
13-
if Mix.Project.get do
14-
Mix.Task.run "loadpaths", ["--no-check"]
15-
Mix.Task.reenable "loadpaths"
16-
Mix.Task.reenable "deps.loadpaths"
8+
if help?(args) do
9+
display_banner()
10+
else
11+
proceed(args)
1712
end
18-
19-
run_task task, args
2013
end
2114

2215
defp load_mixfile(args) do
@@ -54,4 +47,35 @@ defmodule Mix.CLI do
5447
end
5548
end
5649
end
50+
51+
defp proceed(args) do
52+
Mix.Local.append_tasks
53+
54+
args = load_mixfile(args)
55+
{ task, args } = get_task(args)
56+
57+
if Mix.Project.get do
58+
Mix.Task.run "loadpaths", ["--no-check"]
59+
Mix.Task.reenable "loadpaths"
60+
Mix.Task.reenable "deps.loadpaths"
61+
end
62+
63+
run_task task, args
64+
end
65+
66+
defp display_banner() do
67+
run_task "help", []
68+
end
69+
70+
defp help_argument?(s) do
71+
if s do
72+
String.downcase(s) in ["--help", "-h", "-help"]
73+
else
74+
false
75+
end
76+
end
77+
78+
defp help?(args) do
79+
help_argument?(Enum.first(args))
80+
end
5781
end

0 commit comments

Comments
 (0)