Lua: extend pandoc.system module. (#8184)
The module now has the additional functions `list_directory`, `make_directory`, and `remove_directory`. This makes it easier to write cross-platform scripts that need to inspect or modify the file system.
This commit is contained in:
parent
7119fee963
commit
daef24f022
2 changed files with 58 additions and 1 deletions
|
@ -4423,6 +4423,60 @@ Returns:
|
|||
|
||||
- The current working directory (string).
|
||||
|
||||
### list\_directory {#pandoc.system.list_directory}
|
||||
|
||||
`list_directory ([directory])`
|
||||
|
||||
List the contents of a directory.
|
||||
|
||||
Parameters:
|
||||
|
||||
`directory`
|
||||
: Path of the directory whose contents should be listed
|
||||
(string). Defaults to `.`.
|
||||
|
||||
Returns:
|
||||
|
||||
- A table of all entries in `directory` without the special
|
||||
entries `.` and `..`. (list of strings)
|
||||
|
||||
### make\_directory {#pandoc.system.make_directory}
|
||||
|
||||
`make_directory (dirname [, create_parent])`
|
||||
|
||||
Create a new directory which is initially empty, or as near to
|
||||
empty as the operating system allows. The function throws an
|
||||
error if the directory cannot be created, e.g., if the parent
|
||||
directory does not exist or if a directory of the same name is
|
||||
already present.
|
||||
|
||||
If the optional second parameter is provided and truthy, then all
|
||||
directories, including parent directories, are created as
|
||||
necessary.
|
||||
|
||||
Parameters:
|
||||
|
||||
`dirname`
|
||||
: name of the new directory (string)
|
||||
|
||||
`create_parent`
|
||||
: create parent directories if necessary (boolean)
|
||||
|
||||
### remove\_directory {#pandoc.system.remove_directory}
|
||||
|
||||
`remove_directory (dirname [, recursive])`
|
||||
|
||||
Remove an existing, empty directory. If `recursive` is given,
|
||||
then delete the directory and its contents recursively.
|
||||
|
||||
Parameters:
|
||||
|
||||
`dirname`
|
||||
: name of the directory to delete (string)
|
||||
|
||||
`recursive`
|
||||
: delete content recursively (boolean)
|
||||
|
||||
### with\_environment {#pandoc.system.with_environment}
|
||||
|
||||
`with_environment (environment, callback)`
|
||||
|
|
|
@ -16,7 +16,7 @@ module Text.Pandoc.Lua.Module.System
|
|||
|
||||
import HsLua
|
||||
import HsLua.Module.System
|
||||
(arch, env, getwd, os, with_env, with_tmpdir, with_wd)
|
||||
(arch, env, getwd, ls, mkdir, os, rmdir, with_env, with_tmpdir, with_wd)
|
||||
|
||||
-- | Push the pandoc.system module on the Lua stack.
|
||||
documentedModule :: LuaError e => Module e
|
||||
|
@ -30,6 +30,9 @@ documentedModule = Module
|
|||
, moduleFunctions =
|
||||
[ setName "environment" env
|
||||
, setName "get_working_directory" getwd
|
||||
, setName "list_directory" ls
|
||||
, setName "make_directory" mkdir
|
||||
, setName "remove_directory" rmdir
|
||||
, setName "with_environment" with_env
|
||||
, setName "with_temporary_directory" with_tmpdir
|
||||
, setName "with_working_directory" with_wd
|
||||
|
|
Loading…
Add table
Reference in a new issue