Skip to content

Commit

Permalink
Lua: extend pandoc.system module.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tarleb committed Jul 14, 2022
1 parent 12cc140 commit c31f109
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
54 changes: 54 additions & 0 deletions doc/lua-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -4417,6 +4417,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)`
Expand Down
5 changes: 4 additions & 1 deletion src/Text/Pandoc/Lua/Module/System.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c31f109

Please sign in to comment.