diff options
author | Daniel Weipert <code@drogueronin.de> | 2021-12-15 23:14:25 +0100 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2022-01-10 13:28:28 +0100 |
commit | b5dd4f9123ae7464708bd84c76fd7f554bd350c2 (patch) | |
tree | 2f90e2539e4ddb2cc3ca144b30dfc542707db333 | |
parent | f082f8ce234a69a419ec256259dc3ded6abecd71 (diff) |
Add variable command options
-rw-r--r-- | lua/rclone.lua | 55 | ||||
-rw-r--r-- | plugin/rclone.vim | 5 |
2 files changed, 47 insertions, 13 deletions
diff --git a/lua/rclone.lua b/lua/rclone.lua index 54ae939..c584b6b 100644 --- a/lua/rclone.lua +++ b/lua/rclone.lua @@ -205,8 +205,8 @@ end -- 'rclone copy <args>' -- -- @return any -local function copy(remote_section) - local remote, config = get_remote_config(remote_section) +local function copy(options) + local remote, config = get_remote_config(options.remote) if remote == nil then return end @@ -233,8 +233,8 @@ end -- 'rclone copy <args>' -- -- @return any -local function copyFile(remote_section) - local remote, config = get_remote_config(remote_section) +local function copyFile(options) + local remote, config = get_remote_config(options.remote) if remote == nil then return end @@ -267,8 +267,8 @@ end -- 'rclone sync <args>' -- -- @return any -local function sync(remote_section) - local remote, config = get_remote_config(remote_section) +local function sync(options) + local remote, config = get_remote_config(options.remote) if remote == nil then return end @@ -290,9 +290,46 @@ local function sync(remote_section) return config end +-- Table for dynamic command access +local commands = { + copy = copy, + copyFile = copyFile, + sync = sync, +} + +--- +-- Parse args and run specified command +local function run(cmd, ...) + local args = { ... } + if cmd == nil then + print('No command supplied!') + return + end + + if commands[cmd] == nil then + print('Command "' .. cmd .. '" does not exist.') + return + end + + local options = {} + for _, arg in ipairs(args) do + if arg:find('%-%-') == 1 then + options[arg] = true + elseif arg:find('=', 1) == nil then + options['remote'] = arg + else + local param = vim.split(arg, '=') + local key = table.remove(param, 1) + param = table.concat(param, '=') + + options[key] = param + end + end + + commands[cmd](options) +end + return { - copy = copy, - copyFile = copyFile, - sync = sync, + run = run, } diff --git a/plugin/rclone.vim b/plugin/rclone.vim index 31c3f1b..568c839 100644 --- a/plugin/rclone.vim +++ b/plugin/rclone.vim @@ -5,10 +5,7 @@ endif let s:old_cpo = &cpo set cpo&vim -command! -nargs=? RcloneCopy lua require('rclone').copy(<f-args>) -command! -nargs=? RcloneCopyFile lua require('rclone').copyFile(<f-args>) -command! -nargs=? RcloneSync lua require('rclone').sync(<f-args>) - +command! -nargs=+ Rclone lua require('rclone').run(unpack({<f-args>})) let &cpo = s:old_cpo unlet s:old_cpo |