Skip to content

Commit b5478ed

Browse files
committed
add cli.archive and cli.extract
1 parent de0ade7 commit b5478ed

File tree

3 files changed

+112
-1
lines changed

3 files changed

+112
-1
lines changed

xmake/modules/cli/archive.lua

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--!A cross-platform build utility based on Lua
2+
--
3+
-- Licensed under the Apache License, Version 2.0 (the "License");
4+
-- you may not use this file except in compliance with the License.
5+
-- You may obtain a copy of the License at
6+
--
7+
-- http://www.apache.org/licenses/LICENSE-2.0
8+
--
9+
-- Unless required by applicable law or agreed to in writing, software
10+
-- distributed under the License is distributed on an "AS IS" BASIS,
11+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
-- See the License for the specific language governing permissions and
13+
-- limitations under the License.
14+
--
15+
-- Copyright (C) 2015-present, TBOOX Open Source Group.
16+
--
17+
-- @author ruki
18+
-- @file archive.lua
19+
--
20+
21+
-- imports
22+
import("core.base.option")
23+
import("utils.archive.archive")
24+
25+
-- the options
26+
local options = {
27+
{nil, "compress", "kv", nil, "Set the compress algorithm.", values = {"fastest", "faster", "default", "better", "best"}},
28+
{'r', "recurse", "k", nil, "Enable recursive pattern."},
29+
{nil, "excludes", "kv", nil, "Set the excludes patterns.",
30+
"e.g.",
31+
" - xmake l cli.archive --excludes=\"*/dir/*|dir/*\" -o archivefile inputfiles"},
32+
{'o', "archivefile","kv", nil, "The output archive file."},
33+
{nil, "inputfiles", "vs", nil, "The input files."}
34+
}
35+
36+
function main(...)
37+
local argv = table.pack(...)
38+
local args = option.parse(argv, options, "Archive file.",
39+
"",
40+
"Usage: xmake l cli.archive [options]")
41+
local archivefile = assert(args.archivefile, "please set output file!")
42+
local inputfiles = assert(args.inputfiles, "please set input files!")
43+
44+
local opt = {}
45+
opt.recurse = args.recurse
46+
opt.compress = args.compress
47+
if args.excludes then
48+
opt.excludes = args.excludes:split("|")
49+
end
50+
archive(archivefile, inputfiles, opt)
51+
end

xmake/modules/cli/extract.lua

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--!A cross-platform build utility based on Lua
2+
--
3+
-- Licensed under the Apache License, Version 2.0 (the "License");
4+
-- you may not use this file except in compliance with the License.
5+
-- You may obtain a copy of the License at
6+
--
7+
-- http://www.apache.org/licenses/LICENSE-2.0
8+
--
9+
-- Unless required by applicable law or agreed to in writing, software
10+
-- distributed under the License is distributed on an "AS IS" BASIS,
11+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
-- See the License for the specific language governing permissions and
13+
-- limitations under the License.
14+
--
15+
-- Copyright (C) 2015-present, TBOOX Open Source Group.
16+
--
17+
-- @author ruki
18+
-- @file extract.lua
19+
--
20+
21+
-- imports
22+
import("core.base.option")
23+
import("utils.archive.extract")
24+
25+
-- the options
26+
local options = {
27+
{nil, "excludes", "kv", nil, "Set the excludes patterns.",
28+
"e.g.",
29+
" - xmake l cli.extract --excludes=\"*/dir/*|dir/*\" -o outputdir archivefile"},
30+
{'o', "outputdir", "kv", nil, "The output directory."},
31+
{nil, "archivefile","v", nil, "The archive file."}
32+
}
33+
34+
function main(...)
35+
local argv = table.pack(...)
36+
local args = option.parse(argv, options, "Extract file.",
37+
"",
38+
"Usage: xmake l cli.extract [options]")
39+
local archivefile = assert(args.archivefile, "please set archive file!")
40+
local outputdir = assert(args.outputdir, "please set output directory!")
41+
42+
local opt = {}
43+
opt.recurse = args.recurse
44+
if args.excludes then
45+
opt.excludes = args.excludes:split("|")
46+
end
47+
extract(archivefile, outputdir, opt)
48+
end

xmake/modules/utils/archive/archive_xmz.lua

+13-1
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,24 @@
2121
-- imports
2222
import("core.base.option")
2323

24-
-- archive archive file
24+
-- archive file
2525
--
2626
-- @param archivefile the archive file. e.g. *.tar.gz, *.zip, *.7z, *.tar.bz2, ..
2727
-- @param inputfiles the input file or directory or list
2828
-- @param options the options, e.g.. {curdir = "/tmp", recurse = true, compress = "fastest|faster|default|better|best", excludes = {"*/dir/*", "dir/*"}}
2929
--
3030
function main(archivefile, inputfiles, opt)
3131
opt = opt or {}
32+
local files = {}
33+
for _, inputfile in ipairs(inputfiles) do
34+
if os.isdir(inputfile) then
35+
table.join2(files, os.files(path.join(inputfile, opt.recurse and "**" or "*")))
36+
elseif os.isfile(inputfile) then
37+
table.insert(files, inputfile)
38+
end
39+
end
40+
inputfiles = files
41+
42+
print("archivefile", archivefile)
43+
print("inputfiles", inputfiles)
3244
end

0 commit comments

Comments
 (0)