From fae1d44a8c040c20702eddf228befb89b79eda19 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sat, 27 Nov 2021 19:23:17 +0100 Subject: Add comments and slight refactor --- lua/rclone.lua | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/lua/rclone.lua b/lua/rclone.lua index e7c84cd..924b7d8 100644 --- a/lua/rclone.lua +++ b/lua/rclone.lua @@ -1,12 +1,15 @@ local config_file = '' local config_dir = '' +--- +-- Find config file and set global variables +-- +-- @return string local function find_config_file() if config_file ~= '' then return config_file end - -- TODO: find config file local scandir = require('plenary.scandir').scan_dir local Path = require('plenary.path') @@ -17,28 +20,42 @@ local function find_config_file() if string.find(file, 'rclone.conf') then config_file = file config_dir = current_dir.filename - break + + return config_file end end + --if current_dir:is_root() then + if current_dir.filename == '/' then + return '' + end + current_dir = current_dir:parent() end - - return config_file end +--- +-- Get rclone config as JSON +-- and parse to table +-- +-- @return string local function get_config() - -- TODO: rclone config dump --config=find_config_file() local handle = io.popen('rclone config dump --config=' .. find_config_file(), 'r') local config = handle:read('*all'); handle:close() - return config + return vim.fn.json_decode(config) end +--- +-- Get the desired remote config from the config file +-- +-- @param remote string +-- +-- @return string +-- @return table local function get_remote_config(remote) - -- TODO: read json from get_config() and get default remote - local config = vim.fn.json_decode(get_config()) + local config = get_config() local target_remote = nil local target_config = nil @@ -77,8 +94,12 @@ local function get_remote_config(remote) return target_remote, target_config end +--- +-- Call the 'rclone copy' command with config values +-- 'rclone copy $LOCAL_PATH $REMOTE:$REMOTE_PATH --config=find_config_file()' +-- +-- @return any local function copy() - -- TODO: rclone copy $LOCAL_PATH $REMOTE:$REMOTE_PATH --config=find_config_file() local Path = require('plenary.path') local remote, config = get_remote_config() -- cgit v1.2.3