From 9c03508958522b2beeaa2aa289ad82e444d902d8 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 2 Apr 2019 17:27:33 -0300 Subject: Add --global, improve relationship between project and --local --- src/luarocks/cmd.lua | 23 ++++++++++++++--------- src/luarocks/cmd/help.lua | 3 ++- src/luarocks/fs/lua.lua | 2 +- src/luarocks/util.lua | 1 + 4 files changed, 18 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index 93bc5525..eb120c0b 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua @@ -70,9 +70,9 @@ do end process_tree_flags = function(flags, project_dir) - - if cfg.local_by_default then - flags["local"] = true + + if flags["global"] then + cfg.local_by_default = false end if flags["tree"] then @@ -91,18 +91,23 @@ do local root_dir = fs.absolute_name(flags["tree"]) replace_tree(flags, root_dir) end - elseif flags["project-tree"] then - local tree = flags["project-tree"] - table.insert(cfg.rocks_trees, 1, { name = "project", root = tree } ) - loader.load_rocks_trees() - path.use_tree(tree) elseif flags["local"] then if not cfg.home_tree then return nil, "The --local flag is meant for operating in a user's home directory.\n".. "You are running as a superuser, which is intended for system-wide operation.\n".. "To force using the superuser's home, use --tree explicitly." + else + replace_tree(flags, cfg.home_tree) + end + elseif flags["project-tree"] then + local tree = flags["project-tree"] + table.insert(cfg.rocks_trees, 1, { name = "project", root = tree } ) + loader.load_rocks_trees() + path.use_tree(tree) + elseif cfg.local_by_default then + if cfg.home_tree then + replace_tree(flags, cfg.home_tree) end - replace_tree(flags, cfg.home_tree) elseif project_dir then local project_tree = project_dir .. "/lua_modules" table.insert(cfg.rocks_trees, 1, { name = "project", root = project_tree } ) diff --git a/src/luarocks/cmd/help.lua b/src/luarocks/cmd/help.lua index 556929c5..e5f1b799 100644 --- a/src/luarocks/cmd/help.lua +++ b/src/luarocks/cmd/help.lua @@ -45,7 +45,6 @@ function help.command(description, commands, command) assert(type(commands) == "table") if not command then - local conf = cfg.which_config() print_banner() print_section("NAME") util.printout("\t"..program..[[ - ]]..description) @@ -68,6 +67,7 @@ function help.command(description, commands, command) --tree= Which tree to operate on. --local Use the tree in the user's home directory. To enable it, see ']]..program..[[ help path'. + --global Use the system tree when `local_by_default` is `true`. --verbose Display verbose output of commands executed. --timeout= Timeout on network operations, in seconds. 0 means no timeout (wait forever). @@ -89,6 +89,7 @@ function help.command(description, commands, command) end util.printout() util.printout("\tConfiguration files:") + local conf = cfg.config_files util.printout("\t\tSystem : ".. dir.normalize(conf.system.file) .. " (" .. get_status(conf.system.ok) ..")") if conf.user.file then util.printout("\t\tUser : ".. dir.normalize(conf.user.file) .. " (" .. get_status(conf.user.ok) ..")") diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 6ad2b1b8..0273cd53 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -1105,7 +1105,7 @@ function fs_lua.check_command_permissions(flags) if ok then return true else - if flags["local"] then + if flags["local"] or cfg.local_by_default then err = err .. " \n-- please check your permissions." else err = err .. " \n-- you may want to run as a privileged user or use your local tree with --local." diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index dae9307a..aac52344 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -100,6 +100,7 @@ local supported_flags = { ["force"] = true, ["force-fast"] = true, ["from"] = "", + ["global"] = true, ["help"] = true, ["home"] = true, ["homepage"] = "\"\"", -- cgit v1.2.3-55-g6feb