Skip to content

Commit 46713a1

Browse files
authored
feat!: add CLI flag handling (#185)
1 parent 8054458 commit 46713a1

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

apps/expert/lib/expert/application.ex

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,65 @@ defmodule Expert.Application do
1212

1313
@impl true
1414
def start(_type, _args) do
15+
{opts, _argv, _invalid} =
16+
OptionParser.parse(Burrito.Util.Args.argv(),
17+
strict: [version: :boolean, help: :boolean, stdio: :boolean, port: :integer]
18+
)
19+
20+
help_text = """
21+
Expert v#{Expert.vsn()}
22+
23+
The official language server for Elixir
24+
25+
Home page: https://expert-lsp.org
26+
Source code: https://github.com/elixir-lang/expert
27+
28+
expert [flags]
29+
30+
#{IO.ANSI.bright()}FLAGS#{IO.ANSI.reset()}
31+
32+
--stdio Use stdio as the transport mechanism
33+
--port <port> Use TCP as the transport mechanism, with the given port
34+
--help Show this help message
35+
--version Show Expert version
36+
"""
37+
38+
cond do
39+
opts[:help] ->
40+
IO.puts(help_text)
41+
42+
System.halt(0)
43+
44+
opts[:version] ->
45+
IO.puts("#{Expert.vsn()}")
46+
System.halt(0)
47+
48+
true ->
49+
:noop
50+
end
51+
52+
buffer_opts =
53+
cond do
54+
opts[:stdio] ->
55+
[]
56+
57+
is_integer(opts[:port]) ->
58+
IO.puts("Starting on port #{opts[:port]}")
59+
[communication: {GenLSP.Communication.TCP, [port: opts[:port]]}]
60+
61+
true ->
62+
IO.puts(help_text)
63+
64+
System.halt(1)
65+
end
66+
1567
children = [
1668
document_store_child_spec(),
1769
{DynamicSupervisor, Expert.Project.DynamicSupervisor.options()},
1870
{DynamicSupervisor, name: Expert.DynamicSupervisor},
1971
{GenLSP.Assigns, [name: Expert.Assigns]},
2072
{Task.Supervisor, name: :expert_task_queue},
21-
{GenLSP.Buffer, name: Expert.Buffer},
73+
{GenLSP.Buffer, [name: Expert.Buffer] ++ buffer_opts},
2274
{Expert,
2375
name: Expert,
2476
buffer: Expert.Buffer,

0 commit comments

Comments
 (0)