Skip to content

Commit 919f6a3

Browse files
committed
feat: add --help
Content copied from https://luals.github.io/wiki/usage/
1 parent 115a518 commit 919f6a3

File tree

4 files changed

+166
-0
lines changed

4 files changed

+166
-0
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44
<!-- Add all new changes here. They will be moved under a version at release -->
55
* `FIX` incorrect argument skip pattern for `--check_out_path=`, which incorrectly skips the next argument
6+
* `NEW` CLI: added `--help`.
67

78
## 3.13.6
89
`2025-2-6`

script/cli/help.lua

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
--- @class cli.arg
2+
--- @field type? string|string[]
3+
--- @field description string Description of the argument in markdown format.
4+
--- @field example? string
5+
--- @field default? any
6+
7+
--- @type table<string, cli.arg>
8+
local args = {
9+
['--help'] = {
10+
description = [[
11+
Print this message.
12+
]],
13+
},
14+
['--check'] = {
15+
type = 'string',
16+
description = [[
17+
Perform a "diagnosis report" where the results of the diagnosis are written to the logpath.
18+
]],
19+
example = [[--check=C:\Users\Me\path\to\workspace]]
20+
},
21+
['--checklevel'] = {
22+
type = 'string',
23+
description = [[
24+
To be used with --check. The minimum level of diagnostic that should be logged.
25+
Items with lower priority than the one listed here will not be written to the file.
26+
Options include, in order of priority:
27+
28+
- Error
29+
- Warning
30+
- Information
31+
- Hint
32+
]],
33+
default = 'Warning',
34+
example = [[--checklevel=Information]]
35+
},
36+
['--check_format'] = {
37+
type = { 'json', 'pretty' },
38+
description = [[
39+
Output format for the check results.
40+
- 'pretty': results are displayed to stdout in a human-readable format.
41+
- 'json': results are written to a file in JSON format. See --check_out_path
42+
]],
43+
default = 'pretty'
44+
},
45+
['--version'] = {
46+
type = 'string',
47+
description = [[
48+
Get the version of the Lua language server.
49+
This will print it to the command line and immediately exit.
50+
]],
51+
},
52+
['--doc'] = {
53+
type = 'string',
54+
description = [[
55+
Generate documentation from a workspace.
56+
The files will be output in your log path.
57+
]],
58+
example = [[--doc=C:/Users/Me/Documents/myLuaProject/]]
59+
},
60+
['--doc_out_path'] = {
61+
type = 'string',
62+
description = [[
63+
The path to output generated documentation at.
64+
See --doc for more info.
65+
]],
66+
example = [[--doc_out_path=C:/Users/Me/Documents/myLuaProjectDocumentation]]
67+
},
68+
['--logpath'] = {
69+
type = 'string',
70+
description = [[
71+
Where the log should be written to.
72+
]],
73+
default = './log',
74+
example = [[--logpath=D:/luaServer/logs]]
75+
},
76+
['--loglevel'] = {
77+
type = 'string',
78+
description = [[
79+
The minimum level of logging that should appear in the logfile.
80+
Can be used to log more detailed info for debugging and error reporting.
81+
82+
Options:
83+
84+
- error
85+
- warn
86+
- info
87+
- debug
88+
- trace
89+
]],
90+
example = [[--loglevel=trace]]
91+
},
92+
['--metapath'] = {
93+
type = 'string',
94+
description = [[
95+
Where the standard Lua library definition files should be generated to.
96+
]],
97+
default = './meta',
98+
example = [[--metapath=D:/sumnekoLua/metaDefintions]]
99+
},
100+
['--locale'] = {
101+
type = 'string',
102+
description = [[
103+
The language to use. Defaults to en-us.
104+
Options can be found in locale/ .
105+
]],
106+
example = [[--locale=zh-cn]]
107+
},
108+
['--configpath'] = {
109+
type = 'string',
110+
description = [[
111+
The location of the configuration file that will be loaded.
112+
Can be relative to the workspace.
113+
When provided, config files from elsewhere (such as from VS Code) will no longer be loaded.
114+
]],
115+
example = [[--configpath=sumnekoLuaConfig.lua]]
116+
},
117+
['--force-accept-workspace'] = {
118+
type = 'boolean',
119+
description = [[
120+
Allows the use of root/home directory as the workspace.
121+
]]
122+
},
123+
['--socket'] = {
124+
type = 'number',
125+
description = [[
126+
Will communicate to a client over the specified TCP port instead of through stdio.
127+
]],
128+
example = [[--socket=5050]]
129+
},
130+
['--develop'] = {
131+
type = 'boolean',
132+
description = [[
133+
Enables development mode. This allows plugins to write to the logpath.
134+
]]
135+
}
136+
}
137+
138+
for nm, attrs in pairs(args) do
139+
if attrs.type == 'string' then
140+
print(nm .. "=<value>")
141+
else
142+
print(nm)
143+
end
144+
if attrs.description then
145+
local normalized_description = attrs.description:gsub("^%s+", ""):gsub("\n%s+", "\n"):gsub("%s+$", "")
146+
print("\n " .. normalized_description:gsub('\n', '\n '))
147+
end
148+
if attrs.type then
149+
print("\n Type: " .. (type(attrs.type) == "table" and table.concat(attrs.type, ", ") or attrs.type))
150+
end
151+
if attrs.default then
152+
print("\n Default: " .. tostring(attrs.default))
153+
end
154+
if attrs.example then
155+
print("\n Example: " .. attrs.example)
156+
end
157+
print()
158+
end

script/cli/init.lua

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
if _G['HELP'] then
2+
require 'cli.help'
3+
os.exit(0, true)
4+
end
5+
16
if _G['VERSION'] then
27
require 'cli.version'
38
os.exit(0, true)

script/global.d.lua

+2
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,5 @@ THREAD_ID = 1
109109
CHECK_WORKER = ''
110110

111111
QUIET = false
112+
113+
HELP = false

0 commit comments

Comments
 (0)