summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-02-24 16:40:40 +0800
committerruki <[email protected]>2016-02-24 16:40:40 +0800
commitdae473cb200c72b9cd94fcfe04c431e59837012f (patch)
treec10c5d804c50230530e7db8140f2174eb7965824
parentbd2b7e61c8053041aae4f54537641529d6c10d49 (diff)
show main menu for tasks
-rw-r--r--xmake/core/base/main.lua43
-rw-r--r--xmake/core/base/option.lua107
-rw-r--r--xmake/core/base/task.lua51
-rwxr-xr-xxmake/core/tasks/build.lua46
-rwxr-xr-xxmake/core/tasks/config.lua11
-rwxr-xr-xxmake/core/tasks/lua.lua11
-rwxr-xr-xxmake/plugins/doxygen.lua34
-rwxr-xr-xxmake/plugins/macro.lua34
8 files changed, 241 insertions, 96 deletions
diff --git a/xmake/core/base/main.lua b/xmake/core/base/main.lua
index 54008aa21..3e8289ba9 100644
--- a/xmake/core/base/main.lua
+++ b/xmake/core/base/main.lua
@@ -40,47 +40,8 @@ local menu =
-- copyright
, copyright = "Copyright (C) 2015-2016 Ruki Wang, tboox.org\nCopyright (C) 2005-2014 Mike Pall, luajit.org"
- -- build project: xmake
-, main =
- {
- -- usage
- usage = "xmake [action] [options] [target]"
-
- -- description
- , description = "Build the project if no given action."
-
- -- actions
- , actions = action.list
-
- -- options
- , options =
- {
- {'b', "build", "k", nil, "Build project. This is default building mode and optional." }
- , {'u', "update", "k", nil, "Only relink and update the binary files." }
- , {'r', "rebuild", "k", nil, "Rebuild the project." }
-
- , {}
- , {'f', "file", "kv", "xmake.lua", "Read a given xmake.lua file." }
- , {'P', "project", "kv", nil, "Change to the given project directory."
- , "Search priority:"
- , " 1. The Given Command Argument"
- , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR"
- , " 3. The Current Directory" }
-
-
- , {}
- , {'j', "jobs", "kv", nil, "Specifies the number of jobs to build simultaneously" }
- , {'v', "verbose", "k", nil, "Print lots of verbose information." }
- , {nil, "version", "k", nil, "Print the version number and exit." }
- , {'h', "help", "k", nil, "Print this help message and exit." }
-
- , {}
- , {nil, "target", "v", "all", "Build the given target." }
- }
- }
-
- -- the actions: xmake [action]
-, action.menu
+ -- the tasks: xmake [task]
+, task.menu
}
diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua
index 1c8c35573..08269397d 100644
--- a/xmake/core/base/option.lua
+++ b/xmake/core/base/option.lua
@@ -27,8 +27,8 @@ local option = option or {}
local utils = require("base/utils")
local table = require("base/table")
--- save the option menu
-function option._save_menu(menu)
+-- translate the menu
+function option._translate(menu)
-- translate the action menus if exists function
local submenus_all = {}
@@ -46,11 +46,6 @@ function option._save_menu(menu)
end
table.copy2(menu, submenus_all)
- -- translate the actions of the main menu if exists function
- if menu.main and type(menu.main.actions) == "function" then
- menu.main.actions = menu.main.actions()
- end
-
-- translate it if exists function in the option menu
for _, submenu in pairs(menu) do
@@ -90,6 +85,9 @@ function option.init(argv, menu)
-- check
assert(argv and menu)
+ -- translate menu
+ option._translate(menu)
+
-- the main menu
local main = menu.main
assert(main)
@@ -98,9 +96,6 @@ function option.init(argv, menu)
xmake._OPTIONS = {}
xmake._OPTIONS._DEFAULTS = {}
- -- save menu
- option._save_menu(menu)
-
-- parse _ARGV to _OPTIONS
local _iter, _s, _k = ipairs(argv)
while true do
@@ -488,47 +483,83 @@ function option.print_main()
print(main.description)
end
- -- print actions
- if main.actions then
+ -- print tasks
+ if main.tasks then
- -- print header
- print("")
- print("Actions: ")
-
- -- the padding spaces
- local padding = 42
+ -- make task categories
+ local categories = {}
+ for taskname, taskinfo in pairs(main.tasks) do
- -- print actions
- for _, action in ipairs(main.actions) do
+ -- the category name
+ local categoryname = taskinfo.category or "task"
+ if categoryname == "main" then
+ categoryname = "action"
+ end
- -- the action menu
- local action_menu = menu[action]
+ -- the category task
+ local categorytask = categories[categoryname] or {}
+ categories[categoryname] = categorytask
- -- init the action info
- local action_info = " "
- if action_menu and action_menu.shortname then
- action_info = action_info .. action_menu.shortname .. ", "
+ -- add task to the category
+ categorytask[taskname] = taskinfo
+ end
+
+ -- sort categories
+ local categories_sorted = {}
+ for categoryname, categorytask in pairs(categories) do
+ if categoryname == "action" then
+ table.insert(categories_sorted, 1, {categoryname, categorytask})
else
- action_info = action_info .. " "
+ table.insert(categories_sorted, {categoryname, categorytask})
end
+ end
+
+ -- dump tasks by categories
+ for _, categoryinfo in ipairs(categories_sorted) do
+
+ -- the category name and task
+ local categoryname = categoryinfo[1]
+ local categorytask = categoryinfo[2]
+ assert(categoryname and categorytask)
+
+ -- print category name
+ print("")
+ utils.printf("%s%ss: ", string.sub(categoryname, 1, 1):upper(), string.sub(categoryname, 2))
- -- append the action
- action_info = action_info .. action
+ -- the padding spaces
+ local padding = 42
+
+ -- print tasks
+ for taskname, taskinfo in pairs(categorytask) do
+
+ -- the task menu
+ local taskmenu = taskinfo.menu
+ assert(taskmenu)
+
+ -- init the task line
+ local taskline = " "
+ if taskmenu.shortname then
+ taskline = taskline .. taskmenu.shortname .. ", "
+ else
+ taskline = taskline .. " "
+ end
+
+ -- append the task name
+ taskline = taskline .. taskname
- if action_menu then
-- append spaces
- for i = (#action_info), padding do
- action_info = action_info .. " "
+ for i = (#taskline), padding do
+ taskline = taskline .. " "
end
- -- append the action description
- if action_menu.description then
- action_info = action_info .. action_menu.description
+ -- append the task description
+ if taskmenu.description then
+ taskline = taskline .. taskmenu.description
end
- end
- -- print action info
- print(action_info)
+ -- print task line
+ print(taskline)
+ end
end
end
diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua
index 573d8d0d5..333f58edc 100644
--- a/xmake/core/base/task.lua
+++ b/xmake/core/base/task.lua
@@ -55,6 +55,11 @@ function task._interpreter()
-- register api: task()
interp:api_register_scope("task")
+ -- register api: set_task_category()
+ --
+ -- category: main, action, plugin
+ interp:api_register_set_values("task", "task", "category")
+
-- register api: set_task_menu()
interp:api_register_set_values("task", "task", "menu")
@@ -79,13 +84,6 @@ function task._load(filepath)
utils.error(errors)
end
- -- is plugin? mark it
- if path.basename(path.directory(filepath)) == "plugins" then
- for _, v in pairs(results) do
- v.plugin = true
- end
- end
-
-- ok?
return results
end
@@ -128,6 +126,45 @@ end
-- the menu
function task.menu()
+ -- load tasks
+ local tasks = task.tasks()
+ assert(tasks)
+
+ -- make menu
+ local menu = {}
+ for taskname, taskinfo in pairs(tasks) do
+
+ -- has menu?
+ if taskinfo.menu then
+
+ -- main?
+ if taskinfo.category == "main" then
+ menu.main = taskinfo.menu
+ end
+
+ -- add menu
+ menu[taskname] = taskinfo.menu
+ end
+ end
+
+ -- add tasks to the main menu
+ if menu.main then
+
+ -- make tasks for the main menu
+ menu.main.tasks = menu.main.tasks or {}
+ for taskname, taskinfo in pairs(tasks) do
+
+ -- has menu?
+ if taskinfo.menu then
+
+ -- add task
+ menu.main.tasks[taskname] = taskinfo
+ end
+ end
+ end
+
+ -- ok?
+ return menu
end
-- return module: task
diff --git a/xmake/core/tasks/build.lua b/xmake/core/tasks/build.lua
new file mode 100755
index 000000000..43ea3f7e8
--- /dev/null
+++ b/xmake/core/tasks/build.lua
@@ -0,0 +1,46 @@
+-- define task
+task("build")
+
+ -- set category
+ set_task_category("main")
+
+ -- set menu
+ set_task_menu({
+ -- usage
+ usage = "xmake [action] [options] [target]"
+
+ -- description
+ , description = "Build the project if no given action."
+
+ -- actions
+ -- , actions = function () return task.menu(true) end
+
+ -- options
+ , options =
+ {
+ {'b', "build", "k", nil, "Build project. This is default building mode and optional." }
+ , {'u', "update", "k", nil, "Only relink and update the binary files." }
+ , {'r', "rebuild", "k", nil, "Rebuild the project." }
+
+ , {}
+ , {'f', "file", "kv", "xmake.lua", "Read a given xmake.lua file." }
+ , {'P', "project", "kv", nil, "Change to the given project directory."
+ , "Search priority:"
+ , " 1. The Given Command Argument"
+ , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR"
+ , " 3. The Current Directory" }
+
+
+ , {}
+ , {'j', "jobs", "kv", nil, "Specifies the number of jobs to build simultaneously" }
+ , {'v', "verbose", "k", nil, "Print lots of verbose information." }
+ , {nil, "version", "k", nil, "Print the version number and exit." }
+ , {'h', "help", "k", nil, "Print this help message and exit." }
+
+ , {}
+ , {nil, "target", "v", "all", "Build the given target." }
+ }
+ })
+
+
+
diff --git a/xmake/core/tasks/config.lua b/xmake/core/tasks/config.lua
index 09f5d9ef1..add0a3c59 100755
--- a/xmake/core/tasks/config.lua
+++ b/xmake/core/tasks/config.lua
@@ -1,17 +1,20 @@
-- define task
task("config")
+ -- set category
+ set_task_category("action")
+
-- set menu
set_task_menu({
- -- xmake f
- shortname = 'f'
-
-- usage
- , usage = "xmake config|f [options] [target]"
+ usage = "xmake config|f [options] [target]"
-- description
, description = "Configure the project."
+ -- xmake f
+ , shortname = 'f'
+
-- options
, options =
{
diff --git a/xmake/core/tasks/lua.lua b/xmake/core/tasks/lua.lua
index be5bea0d0..8258e5033 100755
--- a/xmake/core/tasks/lua.lua
+++ b/xmake/core/tasks/lua.lua
@@ -1,17 +1,20 @@
-- define task
task("lua")
+ -- set category
+ set_task_category("action")
+
-- set menu
set_task_menu({
- -- xmake l
- shortname = 'l'
-
-- usage
- , usage = "xmake lua|l [options] [script] [arguments]"
+ usage = "xmake lua|l [options] [script] [arguments]"
-- description
, description = "Run the lua script."
+ -- xmake l
+ , shortname = 'l'
+
-- options
, options =
{
diff --git a/xmake/plugins/doxygen.lua b/xmake/plugins/doxygen.lua
index 69e2907b1..14e4a9b14 100755
--- a/xmake/plugins/doxygen.lua
+++ b/xmake/plugins/doxygen.lua
@@ -1,5 +1,37 @@
-- define task
task("doxygen")
+ -- set category
+ set_task_category("plugin")
+
-- set menu
- set_task_menu({})
+ set_task_menu({
+ -- usage
+ usage = "xmake doxygen [options] [name] [arguments]"
+
+ -- description
+ , description = "Generate the doxygen document for the given name"
+
+ -- options
+ , options =
+ {
+ {'f', "file", "kv", nil, "Read a given xmake.lua file." }
+ , {'P', "project", "kv", nil, "Change to the given project directory."
+ , "Search priority:"
+ , " 1. The Given Command Argument"
+ , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR"
+ , " 3. The Current Directory" }
+
+ , {}
+ , {'v', "verbose", "k", nil, "Print lots of verbose information." }
+ , {nil, "version", "k", nil, "Print the version number and exit." }
+ , {'h', "help", "k", nil, "Print this help message and exit." }
+
+ , {}
+ , {nil, "name", "v", "all", "Configure for the given document name." }
+
+ }
+ })
+
+
+
diff --git a/xmake/plugins/macro.lua b/xmake/plugins/macro.lua
index cebb468e4..60ae15e58 100755
--- a/xmake/plugins/macro.lua
+++ b/xmake/plugins/macro.lua
@@ -1,5 +1,37 @@
-- define task
task("macro")
+ -- set category
+ set_task_category("plugin")
+
-- set menu
- set_task_menu({})
+ set_task_menu({
+ -- usage
+ usage = "xmake macro|m [options] [name] [arguments]"
+
+ -- description
+ , description = "Run the given macro"
+
+ -- xmake m
+ , shortname = 'm'
+
+ -- options
+ , options =
+ {
+ {'f', "file", "kv", nil, "Read a given xmake.lua file." }
+ , {'P', "project", "kv", nil, "Change to the given project directory."
+ , "Search priority:"
+ , " 1. The Given Command Argument"
+ , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR"
+ , " 3. The Current Directory" }
+
+ , {}
+ , {'v', "verbose", "k", nil, "Print lots of verbose information." }
+ , {nil, "version", "k", nil, "Print the version number and exit." }
+ , {'h', "help", "k", nil, "Print this help message and exit." }
+
+ , {}
+ , {nil, "name", "v", nil, "Configure for the given macro name." }
+
+ }
+ })