-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.lua
38 lines (31 loc) · 1.2 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require("pl")
ec = require("editorconfig")
local progname = arg[0]
local function print_usage(ret)
print(ec._VERSION)
print("Usage: " .. progname .. " [OPTIONS] FILEPATH1 [FILEPATH2 FILEPATH3 ...]")
-- print("FILEPATH can be a hyphen (-) if you want to path(s) to be read from stdin.")
print()
print("-f Specify conf filename other than \".editorconfig\".")
print("-b Specify version (used by devs to test compatibility).")
print("-h OR --help Print this help message.")
print("-v OR --version Display version information.")
os.exit(ret)
end
flags, params = app.parse_args(arg, {f = true, b = true})
if flags.h or flags.help then print_usage(0) end
if flags.v or flags.version then print(ec._VERSION); os.exit(0) end
if #params == 0 then print_usage(1) end
local function run_editorconfig(path, show_header)
if show_header then
utils.printf("[%s]\n", path)
end
local props, names = ec.parse(path, flags.f, flags.b)
for _, k in ipairs(names) do
utils.printf("%s=%s\n", k, props[k])
end
end
local show_header = not (#params == 1)
for _, path in ipairs(params) do
run_editorconfig(path, show_header)
end