aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-05-24 16:03:06 -0300
committerHisham Muhammad <hisham@gobolinux.org>2018-05-31 11:16:09 -0300
commitadf40aba69130f0fb2630cfa3da70399823d8399 (patch)
tree80ab4cad8e773f663cb4d8cf8018a32c0770be2a
parent9941d6d52c1052d449aec6b77adf95f2d308e320 (diff)
downloadluarocks-adf40aba69130f0fb2630cfa3da70399823d8399.tar.gz
luarocks-adf40aba69130f0fb2630cfa3da70399823d8399.tar.bz2
luarocks-adf40aba69130f0fb2630cfa3da70399823d8399.zip
init: begin implementing `luarocks init`
-rwxr-xr-xsrc/bin/luarocks1
-rw-r--r--src/luarocks/cmd/init.lua68
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
11commands = { 11commands = {
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
2local init = {}
3
4local cfg = require("luarocks.core.cfg")
5local fs = require("luarocks.fs")
6local path = require("luarocks.path")
7local dir = require("luarocks.dir")
8local util = require("luarocks.util")
9local write_rockspec = require("luarocks.cmd.write_rockspec")
10
11init.help_summary = "Initialize a directory for a Lua project using LuaRocks."
12init.help_arguments = "[<name> [<version>]]"
13init.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
28local 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()
36end
37
38--- Driver function for "init" command.
39-- @return boolean: True if succeeded, nil on errors.
40function 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
66end
67
68return init