File tree Expand file tree Collapse file tree 3 files changed +37
-8
lines changed
Expand file tree Collapse file tree 3 files changed +37
-8
lines changed Original file line number Diff line number Diff line change @@ -102,9 +102,9 @@ defmodule Kernel.CLI do
102102
103103 # Process shared options
104104
105- defp process_shared ( [ "-v" | t ] , config ) do
105+ defp process_shared ( [ opt | t ] , config ) when opt in [ "-v" , "--version" ] do
106106 IO . puts "Elixir #{ System . version } "
107- process_shared t , config
107+ System . halt 0
108108 end
109109
110110 defp process_shared ( [ "-pa" , h | t ] , config ) do
Original file line number Diff line number Diff line change @@ -5,10 +5,13 @@ defmodule Mix.CLI do
55 Runs Mix according to the command line arguments.
66 """
77 def run ( args // System . argv ) do
8- if help? ( args ) do
9- display_banner ( )
10- else
11- proceed ( args )
8+ case check_for_shortcuts ( args ) do
9+ :help ->
10+ display_banner ( )
11+ :version ->
12+ display_version ( )
13+ nil ->
14+ proceed ( args )
1215 end
1316 end
1417
@@ -68,6 +71,16 @@ defmodule Mix.CLI do
6871 run_task "help" , [ ]
6972 end
7073
71- defp help? ( [ first_arg | _ ] ) when first_arg in [ "--help" , "-h" , "-help" ] , do: true
72- defp help? ( _ ) , do: false
74+ defp display_version ( ) do
75+ IO . puts "Elixir #{ System . version } "
76+ end
77+
78+ # Check for --help or --version in the args
79+ defp check_for_shortcuts ( [ first_arg | _ ] ) when first_arg in
80+ [ "--help" , "-h" , "-help" ] , do: :help
81+
82+ defp check_for_shortcuts ( [ first_arg | _ ] ) when first_arg in
83+ [ "--version" , "-v" ] , do: :version
84+
85+ defp check_for_shortcuts ( _ ) , do: nil
7386end
Original file line number Diff line number Diff line change @@ -58,6 +58,22 @@ defmodule Mix.CLITest do
5858 end
5959 end
6060
61+ test "--help smoke test " do
62+ in_fixture " only_mixfile ", fn ->
63+ output = mix " --help "
64+ assert output =~ %r" mix compile\s+# Compile source files"
65+ refute output =~ % r "mix invalid"
66+ end
67+ end
68+
69+ test "--version smoke test " do
70+ in_fixture " only_mixfile ", fn ->
71+ output = mix " -- version "
72+ assert output =~ %r" Elixir [ 0 - 9 \. a - z ] +"
73+ refute output =~ %r" Something silly "
74+ end
75+ end
76+
6177 test " help TASK smoke test " do
6278 in_fixture " only_mixfile ", fn ->
6379 output = mix " help compile "
You can’t perform that action at this time.
0 commit comments