summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/rclone.lua55
1 files changed, 46 insertions, 9 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,
}