Skip to content

Commit 5e2f55f

Browse files
authored
fix: better error message when passing invalid flags (#107)
Closes #103
1 parent b8ccf12 commit 5e2f55f

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

lib/next_ls/lsp_supervisor.ex

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@ defmodule NextLS.LSPSupervisor do
55

66
@env Mix.env()
77

8+
defmodule OptionsError do
9+
@moduledoc false
10+
defexception [:message]
11+
12+
@impl true
13+
def exception(options) do
14+
msg = """
15+
Unknown Options: #{Enum.map_join(options, " ", fn {k, v} -> "#{k} #{v}" end)}
16+
17+
Valid options:
18+
19+
--stdio Starts the server using stdio
20+
--port port-number Starts the server using TCP on the given port
21+
"""
22+
23+
%OptionsError{message: msg}
24+
end
25+
end
26+
827
def start_link(init_arg) do
928
Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
1029
end
@@ -14,8 +33,8 @@ defmodule NextLS.LSPSupervisor do
1433
if @env == :test do
1534
:ignore
1635
else
17-
{opts, _} =
18-
OptionParser.parse!(System.argv(),
36+
{opts, _, invalid} =
37+
OptionParser.parse(System.argv(),
1938
strict: [stdio: :boolean, port: :integer]
2039
)
2140

@@ -29,7 +48,7 @@ defmodule NextLS.LSPSupervisor do
2948
[communication: {GenLSP.Communication.TCP, [port: opts[:port]]}]
3049

3150
true ->
32-
raise "Unknown option"
51+
raise OptionsError, invalid
3352
end
3453

3554
children = [

0 commit comments

Comments
 (0)