Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps.run accept dependencies in place of conf #16

Open
pablomayobre opened this issue Sep 6, 2017 · 1 comment
Open

deps.run accept dependencies in place of conf #16

pablomayobre opened this issue Sep 6, 2017 · 1 comment

Comments

@pablomayobre
Copy link
Contributor

pablomayobre commented Sep 6, 2017

deps.run could potentially accept a list of dependencies instead of a conf table. This would be as easy as checking if the table is an array containing strings (there is a schema checking library already in this repository).

This would make it easier to use as a library.

deps.run({ -- Dependency List
  "bump ~> 3",   -- install bump.lua version 3
  "dkjson >= 2", -- install a version of dkjson greater than 2.0
  "repler",      -- install any version of repler, including SCM versions
}, { -- Arguments
  name = "package name", -- Currently provided by t.identity
  from = { -- Currently provided by t.rocks_servers
    "http://alloyed.me/shared/rocks" ,
    "http://luarocks.org"
  },
  tree = "my-rocks-folder", -- Currently provided by t.rocks_tree
  --All the other args still apply (ie: server and only-server)
})

Note that this additional arguments are only available through the library and not exposed to the CLI (although name and tree could)

@pablomayobre
Copy link
Contributor Author

Maybe this could be fixed by adding a base function, ie deps.base which is called by deps.run and can be used without it

local log      = require 'loverocks.log'
local luarocks = require 'loverocks.luarocks'

local deps = {}

function deps.build(parser)
	parser:description
		"Installs all packages listed as dependencies in your conf.lua file."
	parser:option "-s" "--server"
		:description
			"Fetch rocks/rockspecs from this server as a priority."
	parser:option "--only-server"
		:description
			"Fetch rocks/rockspecs from this server, ignoring other servers."
end

function deps.base(dep_list, flags)
	log:fs("luarocks install <> --only-deps")
	log:assert(luarocks.sandbox(flags, function()
		local lr_deps = require 'luarocks.deps'

		local parsed_deps = {}
		for _, s in ipairs(dep_list) do
			table.insert(parsed_deps, lr_deps.parse_dep(s))
		end

		return lr_deps.fulfill_dependencies({
			name = flags.name or 'LOVE_GAME',
			version = "(love)",
			dependencies = parsed_deps
		}, "one")
	end))

	log:info("Dependencies installed succesfully!")
end

function deps.run(conf, args)
	if conf._loverocks_no_config then
		log:error("conf.lua error: %s", conf._loverocks_no_config)
	end
	if not conf.dependencies then
		log:error("please add a dependency table to your conf.lua FIXME: better error")
	end

	local flags = luarocks.make_flags(conf)
	flags.init_rocks = true

	flags.name = conf.identity or "LOVE_GAME"
	assert(type(flags.name) == 'string')

	if args.server then
		table.insert(flags.from, 1, args.server)
	end
	if args.only_server then
		flags.only_from = args.only_server
	end

	deps.base(conf.dependencies, flags)
end

return deps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant