Skip to content

Commit cf42688

Browse files
lewis6991sumneko
authored andcommitted
feat: add --help
Content copied from https://luals.github.io/wiki/usage/
1 parent 1573c28 commit cf42688

File tree

4 files changed

+169
-0
lines changed

4 files changed

+169
-0
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* `FIX` reimplement section `luals.config` in file doc.json
99
* `FIX` incorrect file names in file doc.json
1010
* `FIX` remove extra `./` path prefix in the check report when using `--check=.`
11+
* `NEW` CLI: added `--help`.
1112

1213
## 3.13.6
1314
`2025-2-6`

script/cli/help.lua

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