Skip to content

add --help and --full-version options #8

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions crates/luals/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use std::{env, path::{Path, PathBuf}};

#[tokio::main(flavor = "current_thread")]
async fn main() -> LuaResult<()> {
unsafe {
env::set_var("LUALS_BIN", env!("CARGO_PKG_NAME"));
}
dynamic_set_root();

let lua = unsafe { Lua::unsafe_new() };
Expand Down
2 changes: 1 addition & 1 deletion main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ local function loadArgs()
local lastKey
for _, v in ipairs(arg) do
---@type string?
local key, tail = v:match '^%-%-([%w_]+)(.*)$'
local key, tail = v:match '^%-%-([%w_-]+)(.*)$'
local value
if key then
value = tail:match '=(.+)'
Expand Down
2 changes: 2 additions & 0 deletions script/cli/full_version.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
local version = require 'version'
print(version.getFullVersion())
10 changes: 10 additions & 0 deletions script/cli/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
if _G['HELP'] then
require 'cli.usage'
os.exit(0, true)
end

if _G['FULL_VERSION'] then
require 'cli.full_version'
os.exit(0, true)
end

if _G['VERSION'] then
require 'cli.version'
os.exit(0, true)
Expand Down
2 changes: 2 additions & 0 deletions script/cli/usage.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
print('Usage: ' .. os.getenv("LUALS_BIN") ..
" [--help|--version|--full-version|--check|--check-worker|--doc-update|--doc]" )
36 changes: 36 additions & 0 deletions script/version.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ local function loadVersion()
return version
end

local function loadFullVersion()
local git_config = fsu.loadFile(ROOT / '.git/config')
local repo
local version

if not git_config then
repo = '<Unknown>'
else
repo = git_config:match 'url = %g+github.com/LuaLS/(%g+)'
if not repo then
return
end
end

local phandle = io.popen('git describe --tags')
if phandle == nil then
version = '<Unknown>'
else
version = phandle:read("*l")
phandle:close()
end

if not version then
version = '<Unknown>'
end
return repo .. ' ' .. version
end

local m = {}

function m.getVersion()
Expand All @@ -27,4 +55,12 @@ function m.getVersion()
return m.version
end

function m.getFullVersion()
if not m.full_version then
m.full_version = loadFullVersion() or '<Unknown>'
end

return m.full_version
end

return m