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

Commit c2a8b6e

Browse files
authored
Use plenary.path for checking file existance
1 parent 3a3be5c commit c2a8b6e

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ require('yabs'):setup({
101101
optional = {
102102
command = 'echo runs on condition',
103103
-- You can specify a condition which determines whether to enable a
104-
-- specific task (it could be your custom function)
104+
-- specific task
105+
-- It should be a function that returns boolean,
106+
-- not a boolean directly
107+
-- Here we use a helper from yabs that returns such function
108+
-- to check if the files exists
105109
condition = require('yabs.conditions').file_exists('filename.txt'),
106110
},
107111
},

lua/yabs/conditions/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
local Path = require('plenary.path')
12
local M = {}
23

34
function M.file_exists(file)
45
return function()
5-
return require('yabs.utils').file_exists(file)
6+
return Path:new(file):exists()
67
end
78
end
89

lua/yabs/init.lua

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
local Path = require('plenary.path')
2+
local Language = require('yabs.language')
3+
local Task = require('yabs.task')
4+
local utils = require('yabs.utils')
5+
local scopes = Task.scopes
6+
17
local Yabs = {
28
default_output = nil,
39
default_type = nil,
@@ -8,11 +14,6 @@ local Yabs = {
814
local did_config = false
915
local did_setup = false
1016

11-
local Language = require('yabs.language')
12-
local Task = require('yabs.task')
13-
local utils = require('yabs.utils')
14-
local scopes = Task.scopes
15-
1617
function Yabs.run_command(...)
1718
local args = { ... }
1819
local cmd = args[1]
@@ -255,8 +256,9 @@ function Yabs:run_default_task()
255256
end
256257

257258
function Yabs:load_config_file()
258-
if utils.file_exists('.yabs') then
259-
local config = dofile(vim.loop.cwd() .. '/.yabs')
259+
local yabs = Path:new('.yabs')
260+
if yabs:exists() then
261+
local config = dofile(yabs.filename)
260262
if not config then
261263
utils.notify(
262264
'yabs: deprecation notice: calling `yabs:setup()` in a .yabs file is now deprecated.',

lua/yabs/utils.lua

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ function M.run_command(cmd, output, opts)
2424
output:run(cmd, opts)
2525
end
2626

27-
function M.file_exists(file)
28-
local f = io.open(file, 'rb')
29-
if f then
30-
f:close()
31-
end
32-
return f ~= nil
33-
end
34-
3527
function M.notify(msg, log_level)
3628
vim.notify(msg, log_level, { title = 'Yabs' })
3729
end

0 commit comments

Comments
 (0)