diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-05-24 16:03:06 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-05-31 11:16:09 -0300 |
commit | adf40aba69130f0fb2630cfa3da70399823d8399 (patch) | |
tree | 80ab4cad8e773f663cb4d8cf8018a32c0770be2a | |
parent | 9941d6d52c1052d449aec6b77adf95f2d308e320 (diff) | |
download | luarocks-adf40aba69130f0fb2630cfa3da70399823d8399.tar.gz luarocks-adf40aba69130f0fb2630cfa3da70399823d8399.tar.bz2 luarocks-adf40aba69130f0fb2630cfa3da70399823d8399.zip |
init: begin implementing `luarocks init`
-rwxr-xr-x | src/bin/luarocks | 1 | ||||
-rw-r--r-- | src/luarocks/cmd/init.lua | 68 |
2 files changed, 69 insertions, 0 deletions
diff --git a/src/bin/luarocks b/src/bin/luarocks index 066c72e3..583b50b8 100755 --- a/src/bin/luarocks +++ b/src/bin/luarocks | |||
@@ -10,6 +10,7 @@ program_description = "LuaRocks main command-line interface" | |||
10 | 10 | ||
11 | commands = { | 11 | commands = { |
12 | help = "luarocks.cmd.help", | 12 | help = "luarocks.cmd.help", |
13 | init = "luarocks.cmd.init", | ||
13 | pack = "luarocks.cmd.pack", | 14 | pack = "luarocks.cmd.pack", |
14 | unpack = "luarocks.cmd.unpack", | 15 | unpack = "luarocks.cmd.unpack", |
15 | build = "luarocks.cmd.build", | 16 | build = "luarocks.cmd.build", |
diff --git a/src/luarocks/cmd/init.lua b/src/luarocks/cmd/init.lua new file mode 100644 index 00000000..f4309945 --- /dev/null +++ b/src/luarocks/cmd/init.lua | |||
@@ -0,0 +1,68 @@ | |||
1 | |||
2 | local init = {} | ||
3 | |||
4 | local cfg = require("luarocks.core.cfg") | ||
5 | local fs = require("luarocks.fs") | ||
6 | local path = require("luarocks.path") | ||
7 | local dir = require("luarocks.dir") | ||
8 | local util = require("luarocks.util") | ||
9 | local write_rockspec = require("luarocks.cmd.write_rockspec") | ||
10 | |||
11 | init.help_summary = "Initialize a directory for a Lua project using LuaRocks." | ||
12 | init.help_arguments = "[<name> [<version>]]" | ||
13 | init.help = [[ | ||
14 | <name> is the project name. | ||
15 | <version> is an optional project version. | ||
16 | |||
17 | --license="<string>" A license string, such as "MIT/X11" or "GNU GPL v3". | ||
18 | --summary="<txt>" A short one-line description summary. | ||
19 | --detailed="<txt>" A longer description string. | ||
20 | --homepage=<url> Project homepage. | ||
21 | --lua-version=<ver> Supported Lua versions. Accepted values are "5.1", "5.2", | ||
22 | "5.3", "5.1,5.2", "5.2,5.3", or "5.1,5.2,5.3". | ||
23 | --rockspec-format=<ver> Rockspec format version, such as "1.0" or "1.1". | ||
24 | --lib=<lib>[,<lib>] A comma-separated list of libraries that C files need to | ||
25 | link to. | ||
26 | ]] | ||
27 | |||
28 | local function write_gitignore() | ||
29 | if fs.exists(".gitignore") then | ||
30 | return | ||
31 | end | ||
32 | local fd = io.open(".gitignore", "w") | ||
33 | fd:write("lua_modules\n") | ||
34 | fd:write("lua\n") | ||
35 | fd:close() | ||
36 | end | ||
37 | |||
38 | --- Driver function for "init" command. | ||
39 | -- @return boolean: True if succeeded, nil on errors. | ||
40 | function init.command(flags, name, version) | ||
41 | |||
42 | local pwd = fs.current_dir() | ||
43 | |||
44 | if not name then | ||
45 | name = dir.base_name(pwd) | ||
46 | end | ||
47 | |||
48 | util.printout("Initializing project " .. name) | ||
49 | |||
50 | local ok, err = write_rockspec.command(flags, name, version or "dev", pwd) | ||
51 | if not ok then | ||
52 | util.printerr(err) | ||
53 | end | ||
54 | |||
55 | write_gitignore() | ||
56 | |||
57 | fs.make_dir("lua_modules/lib/luarocks/rocks-" .. cfg.lua_version) | ||
58 | local tree = dir.path(pwd, "lua_modules") | ||
59 | |||
60 | fs.wrap_script(arg[0], "luarocks", nil, nil, "--tree", tree) | ||
61 | |||
62 | path.use_tree(tree) | ||
63 | fs.wrap_script(nil, "lua") | ||
64 | |||
65 | return true | ||
66 | end | ||
67 | |||
68 | return init | ||