-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc_join.lua
More file actions
42 lines (35 loc) · 1.21 KB
/
doc_join.lua
File metadata and controls
42 lines (35 loc) · 1.21 KB
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
39
40
41
42
function add_file(table,filepath)
local path = dtw.newPath(filepath)
local extension = path.get_extension()
print("Joining file: " .. filepath, " with extension: " .. extension)
local content = "- file:".. filepath .. "\n"
content = content .. "~~~" .. extension .. "\n"
content = content .. dtw.load_file(filepath)
content = content .. "\n~~~\n"
table[#table + 1] = content
end
local entries_size = argv.get_flag_size({ "entries","e" })
if entries_size == 0 then
print("No entries provided. Use --entries to specify files or directories.")
return
end
local output_file = argv.get_flag_arg_by_index({ "output" ,"o"},1)
if not output_file then
print("No output file specified. Use --output to specify the output file.")
return
end
local content = {}
for i = 1,entries_size do
local entry = argv.get_flag_arg_by_index({ "entries" }, i)
if dtw.isfile(entry) then
add_file(content, entry)
end
if dtw.isdir(entry) then
local files = dtw.list_files_recursively(entry,true)
for j = 1,#files do
add_file(content, files[j])
end
end
end
local final_content = table.concat(content, "\n\n")
dtw.write_file(output_file, final_content)