From 8455ba75dd91299501b5f1e9962fa3a654802177 Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Sun, 20 Aug 2023 19:02:18 -0400 Subject: [PATCH] feat(cli): --version flag (#193) This allows you to fetch the version with `nextls --version` --- lib/next_ls/lsp_supervisor.ex | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/next_ls/lsp_supervisor.ex b/lib/next_ls/lsp_supervisor.ex index 467f2697..ba3ab535 100644 --- a/lib/next_ls/lsp_supervisor.ex +++ b/lib/next_ls/lsp_supervisor.ex @@ -33,12 +33,18 @@ defmodule NextLS.LSPSupervisor do if @env == :test do :ignore else - {m, f, a} = if @env == :prod, do: {Burrito.Util.Args, :get_arguments, []}, else: {System, :argv, []} + {m, f, a} = + if @env == :prod, do: {Burrito.Util.Args, :get_arguments, []}, else: {System, :argv, []} argv = apply(m, f, a) {opts, _, invalid} = - OptionParser.parse(argv, strict: [stdio: :boolean, port: :integer]) + OptionParser.parse(argv, strict: [version: :boolean, stdio: :boolean, port: :integer]) + + if opts[:version] do + IO.puts("#{NextLS.version()}") + System.halt(0) + end buffer_opts = cond do @@ -56,7 +62,11 @@ defmodule NextLS.LSPSupervisor do auto_update = if "NEXTLS_AUTO_UPDATE" |> System.get_env("false") |> String.to_existing_atom() do [ - binpath: System.get_env("NEXTLS_BINPATH", Path.expand("~/.cache/elixir-tools/nextls/bin/nextls")), + binpath: + System.get_env( + "NEXTLS_BINPATH", + Path.expand("~/.cache/elixir-tools/nextls/bin/nextls") + ), api_host: System.get_env("NEXTLS_GITHUB_API", "https://api.github.com"), github_host: System.get_env("NEXTLS_GITHUB", "https://github.com"), current_version: Version.parse!(NextLS.version())