Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Use plenary.path for checking file existance
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatur authored Dec 11, 2021
1 parent 3a3be5c commit c2a8b6e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ require('yabs'):setup({
optional = {
command = 'echo runs on condition',
-- You can specify a condition which determines whether to enable a
-- specific task (it could be your custom function)
-- specific task
-- It should be a function that returns boolean,
-- not a boolean directly
-- Here we use a helper from yabs that returns such function
-- to check if the files exists
condition = require('yabs.conditions').file_exists('filename.txt'),
},
},
Expand Down
3 changes: 2 additions & 1 deletion lua/yabs/conditions/init.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
local Path = require('plenary.path')
local M = {}

function M.file_exists(file)
return function()
return require('yabs.utils').file_exists(file)
return Path:new(file):exists()
end
end

Expand Down
16 changes: 9 additions & 7 deletions lua/yabs/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
local Path = require('plenary.path')
local Language = require('yabs.language')
local Task = require('yabs.task')
local utils = require('yabs.utils')
local scopes = Task.scopes

local Yabs = {
default_output = nil,
default_type = nil,
Expand All @@ -8,11 +14,6 @@ local Yabs = {
local did_config = false
local did_setup = false

local Language = require('yabs.language')
local Task = require('yabs.task')
local utils = require('yabs.utils')
local scopes = Task.scopes

function Yabs.run_command(...)
local args = { ... }
local cmd = args[1]
Expand Down Expand Up @@ -255,8 +256,9 @@ function Yabs:run_default_task()
end

function Yabs:load_config_file()
if utils.file_exists('.yabs') then
local config = dofile(vim.loop.cwd() .. '/.yabs')
local yabs = Path:new('.yabs')
if yabs:exists() then
local config = dofile(yabs.filename)
if not config then
utils.notify(
'yabs: deprecation notice: calling `yabs:setup()` in a .yabs file is now deprecated.',
Expand Down
8 changes: 0 additions & 8 deletions lua/yabs/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ function M.run_command(cmd, output, opts)
output:run(cmd, opts)
end

function M.file_exists(file)
local f = io.open(file, 'rb')
if f then
f:close()
end
return f ~= nil
end

function M.notify(msg, log_level)
vim.notify(msg, log_level, { title = 'Yabs' })
end
Expand Down

0 comments on commit c2a8b6e

Please sign in to comment.