Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): --help flag #194

Merged
merged 1 commit into from
Aug 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 36 additions & 25 deletions lib/next_ls/lsp_supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,6 @@ defmodule NextLS.LSPSupervisor do

@env Mix.env()

defmodule OptionsError do
@moduledoc false
defexception [:message]

@impl true
def exception(options) do
msg = """
Unknown Options: #{Enum.map_join(options, " ", fn {k, v} -> "#{k} #{v}" end)}

Valid options:

--stdio Starts the server using stdio
--port port-number Starts the server using TCP on the given port
"""

%OptionsError{message: msg}
end
end

def start_link(init_arg) do
Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
end
Expand All @@ -38,12 +19,40 @@ defmodule NextLS.LSPSupervisor do

argv = apply(m, f, a)

{opts, _, invalid} =
OptionParser.parse(argv, strict: [version: :boolean, stdio: :boolean, port: :integer])
{opts, _, _invalid} =
OptionParser.parse(argv, strict: [version: :boolean, help: :boolean, stdio: :boolean, port: :integer])

help_text = """
Next LS v#{NextLS.version()}

The langauge server for Elixir that #{IO.ANSI.italic()}#{IO.ANSI.bright()}just#{IO.ANSI.reset()} works.

if opts[:version] do
IO.puts("#{NextLS.version()}")
System.halt(0)
Author: Mitchell Hanberg
Home page: https://www.elixir-tools.dev/next-ls
Source code: https://github.com/elixir-tools/next-ls

nextls [flags]

#{IO.ANSI.bright()}FLAGS#{IO.ANSI.reset()}

--stdio Use stdio as the transport mechanism
--tcp <port> Use TCP as the transport mechanism, with the given port
--help Show help
--version Show nextls version
"""

cond do
opts[:help] ->
IO.puts(help_text)

System.halt(0)

opts[:version] ->
IO.puts("#{NextLS.version()}")
System.halt(0)

true ->
:noop
end

buffer_opts =
Expand All @@ -56,7 +65,9 @@ defmodule NextLS.LSPSupervisor do
[communication: {GenLSP.Communication.TCP, [port: opts[:port]]}]

true ->
raise OptionsError, invalid
IO.puts(help_text)

System.halt(1)
end

auto_update =
Expand Down
Loading