summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-10-23 00:32:25 +0800
committerruki <[email protected]>2020-10-23 00:32:25 +0800
commita5978fb4707fe52520a5c4e5c2ba10a1aee095fe (patch)
tree4cdd8e120520821322af3752f03cd59d7ab7d4b1
parent640e807fdd4ff05534d784f6d706e0c990e63c6e (diff)
improve xrepo logo
-rw-r--r--xmake/core/base/option.lua7
-rw-r--r--xmake/core/sandbox/modules/import/core/base/option.lua4
-rw-r--r--xmake/modules/private/xrepo/main.lua27
3 files changed, 29 insertions, 9 deletions
diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua
index ef6cac2e4..28710df38 100644
--- a/xmake/core/base/option.lua
+++ b/xmake/core/base/option.lua
@@ -484,7 +484,7 @@ function option.show_update_tips()
end
-- show logo
-function option.show_logo(logo)
+function option.show_logo(logo, opt)
-- define logo
logo = logo or [[
@@ -498,15 +498,16 @@ function option.show_logo(logo)
]]
-- make rainbow for logo
+ opt = opt or {}
if colors.truecolor() or colors.color256() then
local lines = {}
- local seed = 236
+ local seed = opt.seed or 236
for _, line in ipairs(logo:split("\n")) do
local i = 0
local line2 = ""
line:gsub(".", function (c)
local code = colors.truecolor() and colors.rainbow24(i, seed) or colors.rainbow256(i, seed)
- line2 = string.format("%s${%s}%s", line2, code, c)
+ line2 = string.format("%s${%s %s}%s", line2, opt.bright and "bright" or "", code, c)
i = i + 1
end)
table.insert(lines, line2)
diff --git a/xmake/core/sandbox/modules/import/core/base/option.lua b/xmake/core/sandbox/modules/import/core/base/option.lua
index 2b527dd46..802007630 100644
--- a/xmake/core/sandbox/modules/import/core/base/option.lua
+++ b/xmake/core/sandbox/modules/import/core/base/option.lua
@@ -57,8 +57,8 @@ function sandbox_core_base_option.defaults()
end
-- show logo
-function sandbox_core_base_option.show_logo(logo)
- option.show_logo(logo)
+function sandbox_core_base_option.show_logo(logo, opt)
+ option.show_logo(logo, opt)
end
-- show options
diff --git a/xmake/modules/private/xrepo/main.lua b/xmake/modules/private/xrepo/main.lua
index d89201f62..78eec9507 100644
--- a/xmake/modules/private/xrepo/main.lua
+++ b/xmake/modules/private/xrepo/main.lua
@@ -50,7 +50,7 @@ function _main_show_help()
by ruki, xmake.io
]]
- option.show_logo(logo)
+ option.show_logo(logo, {seed = 680, bright = true})
-- show usage
cprint("${bright}Usage: $${clear cyan}xrepo [action] [options]")
@@ -59,18 +59,37 @@ function _main_show_help()
option.show_options(_main_options)
end
+-- parse options
+function _parse_options(...)
+
+ -- get action and arguments
+ local argv = table.pack(...)
+ local action = nil
+ if #argv > 0 and not argv[1]:startswith('-') then
+ action = argv[1]
+ argv = table.slice(argv, 2)
+ end
+
+ -- parse argument options
+ local opt, errors = option.raw_parse(argv, _main_options)
+ if opt then
+ opt.action = action
+ end
+ return opt, errors
+end
+
-- main entry
function main(...)
-- parse argument options
- local mainopt, errors = option.raw_parse(table.pack(...), _main_options)
+ local mainopt, errors = _parse_options(...)
if not mainopt then
- _main_show_help()
+ _main_show_help() -- TODO
raise(errors)
end
-- help?
- if mainopt.help then
+ if mainopt.help or not mainopt.action then
_main_show_help()
return
end