Skip to content

Commit cf7d329

Browse files
Improve DevEx when Mix commands receive no arguments (#14853)
Some mix commands fail when no argument is given. Before this PR: ``` $ mix archive.uninstall ** (Mix) No argument was given to uninstall command $ mix cmd ** (Mix) Expected at least one argument in mix cmd $ mix escript.build ** (Mix) Could not generate escript, please set :main_module in your project configuration (under :escript option) to a module that implements main/1 $ mix escript.install ** (Mix) Could not generate escript, please set :main_module in your project configuration (under :escript option) to a module that implements main/1 $ mix escript.uninstall ** (Mix) No argument was given to uninstall command $ mix eval ** (Mix) "mix eval" expects a single string to evaluate as argument $ mix new ** (Mix) Expected PATH to be given, please use "mix new PATH" $ mix xref ** (Mix) xref doesn't support this command. For more information run "mix help xref" ``` With this PR: ``` $ mix archive.uninstall ** (Mix) No argument was given to uninstall command. Use "mix archive.uninstall PATH" or run "mix help archive.uninstall" for more information $ mix cmd ** (Mix) No argument was given to mix cmd. Run "mix help cmd" for more information $ mix escript.build ** (Mix) Could not generate escript, please set :main_module in your project configuration (under :escript option) to a module that implements main/1. Run "mix help escript.build" for more information $ mix escript.install ** (Mix) Could not generate escript, please set :main_module in your project configuration (under :escript option) to a module that implements main/1. Run "mix help escript.build" for more information $ mix escript.uninstall ** (Mix) No argument was given to uninstall command. Use "mix archive.uninstall PATH" or run "mix help archive.uninstall" for more information $ mix eval ** (Mix) "mix eval" expects a single string to evaluate as argument. Run "mix help eval" for more information $ mix new ** (Mix) Expected PATH to be given. Use "mix new PATH" or run "mix help new" for more information $ mix xref ** (Mix) No argument was given to xref command. Run "mix help xref" for more information ```
1 parent 7eb5b3a commit cf7d329

File tree

8 files changed

+25
-10
lines changed

8 files changed

+25
-10
lines changed

lib/mix/lib/mix/local/installer.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,10 @@ defmodule Mix.Local.Installer do
315315
nil
316316
end
317317
else
318-
Mix.raise("No argument was given to uninstall command")
318+
Mix.raise(
319+
"No argument was given to uninstall command. " <>
320+
" Use \"mix archive.uninstall PATH\" or run \"mix help archive.uninstall\" for more information"
321+
)
319322
end
320323
end
321324

lib/mix/lib/mix/tasks/cmd.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ defmodule Mix.Tasks.Cmd do
100100
{opts, args} = OptionParser.parse_head!(args, strict: @switches)
101101

102102
if args == [] do
103-
Mix.raise("Expected at least one argument in mix cmd")
103+
Mix.raise("No argument was given to mix cmd. Run \"mix help cmd\" for more information")
104104
end
105105

106106
apps =

lib/mix/lib/mix/tasks/escript.build.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ defmodule Mix.Tasks.Escript.Build do
154154
if !main do
155155
error_message =
156156
"Could not generate escript, please set :main_module " <>
157-
"in your project configuration (under :escript option) to a module that implements main/1"
157+
"in your project configuration (under :escript option) to a module that implements main/1. " <>
158+
"Run \"mix help escript.build\" for more information"
158159

159160
Mix.raise(error_message)
160161
end

lib/mix/lib/mix/tasks/eval.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ defmodule Mix.Tasks.Eval do
9797
end
9898

9999
_ ->
100-
Mix.raise("\"mix eval\" expects a single string to evaluate as argument")
100+
Mix.raise(
101+
"\"mix eval\" expects a single string to evaluate as argument. " <>
102+
"Run \"mix help eval\" for more information"
103+
)
101104
end
102105
end
103106
end

lib/mix/lib/mix/tasks/new.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ defmodule Mix.Tasks.New do
6464

6565
case argv do
6666
[] ->
67-
Mix.raise("Expected PATH to be given, please use \"mix new PATH\"")
67+
Mix.raise(
68+
"Expected PATH to be given. " <>
69+
"Use \"mix new PATH\" or run \"mix help new\" for more information"
70+
)
6871

6972
[path | _] ->
7073
app = opts[:app] || Path.basename(Path.expand(path))

lib/mix/lib/mix/tasks/xref.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,9 @@ defmodule Mix.Tasks.Xref do
470470
)
471471

472472
_ ->
473-
Mix.raise("xref doesn't support this command. For more information run \"mix help xref\"")
473+
Mix.raise(
474+
"No argument was given to xref command. Run \"mix help xref\" for more information"
475+
)
474476
end
475477
end
476478

lib/mix/test/mix/tasks/new_test.exs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,11 @@ defmodule Mix.Tasks.NewTest do
223223
end)
224224

225225
in_tmp("new without a specified path", fn ->
226-
assert_raise Mix.Error, "Expected PATH to be given, please use \"mix new PATH\"", fn ->
227-
Mix.Tasks.New.run([])
228-
end
226+
assert_raise Mix.Error,
227+
"Expected PATH to be given. Use \"mix new PATH\" or run \"mix help new\" for more information",
228+
fn ->
229+
Mix.Tasks.New.run([])
230+
end
229231
end)
230232
end
231233

lib/mix/test/mix/tasks/xref_test.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ defmodule Mix.Tasks.XrefTest do
177177

178178
test "no argument gives error" do
179179
in_fixture("no_mixfile", fn ->
180-
message = "xref doesn't support this command. For more information run \"mix help xref\""
180+
message =
181+
"No argument was given to xref command. Run \"mix help xref\" for more information"
181182

182183
assert_raise Mix.Error, message, fn ->
183184
assert Mix.Task.run("xref", ["callers"]) == :error

0 commit comments

Comments
 (0)