Skip to content

Commit c6338ff

Browse files
authored
feat(controller): provide update option (#57)
1 parent 8ac2ceb commit c6338ff

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ require('lazy').setup({
8080
'linrongbin16/colorbox.nvim',
8181
lazy = false, -- don't lazy this plugin if it provides the main colorscheme
8282
priority = 1000, -- load this plugin before all other start plugins
83-
build = function() require('colorbox').install() end,
83+
build = function() require('colorbox').update() end,
8484
config = function() require('colorbox').setup() end,
8585
}
8686
})
@@ -92,16 +92,16 @@ require('lazy').setup({
9292
require('pckr').add({
9393
{
9494
'linrongbin16/colorbox.nvim',
95-
run = function() require('colorbox').install() end,
95+
run = function() require('colorbox').update() end,
9696
config = function() require('colorbox').setup() end,
9797
}
9898
})
9999
```
100100

101-
If you have issues on running multiple git clone/pull commands, try set `concurrency=1` in the `install` API:
101+
If you have issues on running multiple git clone/pull commands, try set `concurrency=1` in the `update` API:
102102

103103
```lua
104-
require('colorbox').install({
104+
require('colorbox').update({
105105
--- @type integer
106106
concurrency = 4,
107107
})
@@ -111,8 +111,8 @@ require('colorbox').install({
111111

112112
You can use command `Colorbox` to control the colorschemes player:
113113

114-
- `Colorbox reinstall`: clean & re-install git submodules.
115-
- **Note:** use `Colorbox reinstall concurrency=1` to specify the `concurrency` parameters.
114+
- `Colorbox update/reinstall`: update, or clean & re-install git submodules.
115+
- **Note:** use `concurrency=1` to specify the `concurrency` parameters.
116116
- `Colorbox next/prev/shuffle` (todo): next color, previous color, next random color (even you didn't configure the `shuffle` policy).
117117
- `Colorbox pause/restart` (todo): stay on current color (disable timing config, e.g. fixed interval, by filetype timings), restart to continue change colors (enable timing config).
118118

lua/colorbox.lua

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ local function _timing()
220220
end
221221

222222
--- @param opts {concurrency:integer}?
223-
local function install(opts)
223+
local function update(opts)
224224
opts = opts or { concurrency = 4 }
225225
opts.concurrency = type(opts.concurrency) == "number"
226226
and math.max(opts.concurrency, 1)
@@ -410,8 +410,8 @@ local function install(opts)
410410
end
411411

412412
--- @deprecated
413-
local function update(opts)
414-
return install(opts)
413+
local function install(opts)
414+
return update(opts)
415415
end
416416

417417
local function _clean()
@@ -432,10 +432,9 @@ local function _clean()
432432
logger.info("cleaned directory: %s", shorten_pack_dir)
433433
end
434434

435-
--- @param args string
436-
local function _reinstall(args)
437-
_clean()
438-
435+
--- @param args string?
436+
--- @return colorbox.Options?
437+
local function _parse_update_args(args)
439438
local opts = nil
440439
if type(args) == "string" and string.len(vim.trim(args)) > 0 then
441440
local args_splits =
@@ -444,10 +443,22 @@ local function _reinstall(args)
444443
opts = { concurrency = tonumber(args_splits[2]) }
445444
end
446445
end
447-
install(opts)
446+
return opts
447+
end
448+
449+
--- @param args string
450+
local function _update(args)
451+
update(_parse_update_args(args))
452+
end
453+
454+
--- @param args string
455+
local function _reinstall(args)
456+
_clean()
457+
update(_parse_update_args(args))
448458
end
449459

450460
local CONTROLLERS_MAP = {
461+
update = _update,
451462
reinstall = _reinstall,
452463
}
453464

@@ -510,7 +521,7 @@ local function setup(opts)
510521
bang = true,
511522
desc = Configs.command.desc,
512523
complete = function(ArgLead, CmdLine, CursorPos)
513-
return { "reinstall" }
524+
return { "update", "reinstall" }
514525
end,
515526
}
516527
)

0 commit comments

Comments
 (0)