Namespace: joker.os
v1.0Contents
Summary
Provides a platform-independent interface to operating system functionality.
Index
- args
- chdir
- close
- create
- create-temp
- cwd
- env
- exec
- exists?
- exit
- get-env
- ls
- mkdir
- mkdir-temp
- open
- remove
- remove-all
- set-env
- sh
- sh-from
- stat
- temp-dir
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
(None.)
Variables
-
(None.)
Functions, Macros, and Special Forms
-
args
Function v1.0(args)
Returns a sequence of the command line arguments, starting with the program name (normally, joker).
-
chdir
Function v1.0(chdir dirname)
Chdir changes the current working directory to the named directory. If there is an error, an exception will be thrown. Returns nil.
-
close
Function v1.0(close f)
Closes the file, rendering it unusable for I/O.
-
create
Function v1.0(create name)
Creates the named file with mode 0666 (before umask), truncating it if it already exists.
-
create-temp
Function v1.0(create-temp dir pattern)
Creates a new temporary file in the directory dir, opens the file for reading and writing,
and returns the resulting File. The filename is generated by taking pattern and adding a
random string to the end. If pattern includes a "*", the random string replaces the last "*".
If dir is the empty string, uses the default directory for temporary files (see joker.os/temp-dir).
Multiple programs calling joker.os/make-temp-file simultaneously will not choose the same file.
The caller can use (name f) to find the pathname of the file.
It is the caller's responsibility to remove the file when no longer needed. -
cwd
Function v1.0(cwd)
Returns a rooted path name corresponding to the current directory. If the current directory can
be reached via multiple paths (due to symbolic links), cwd may return any one of them. -
env
Function v1.0(env)
Returns a map representing the environment.
-
exec
Function v1.0(exec name opts)
Executes the named program with the given arguments. opts is a map with the following keys (all optional):
:args - vector of arguments (all arguments must be strings),
:dir - if specified, working directory will be set to this value before executing the program,
:stdin - if specified, provides stdin for the program. Can be either a string or an IOReader.
If it's a string, the string's content will serve as stdin for the program. IOReader can be, for example,
*in* (in which case Joker's stdin will be redirected to the program's stdin) or the value returned by (joker.os/open).
:stdout - if specified, must be an IOWriter. It can be, for example, *out* (in which case the program's stdout will be redirected
to Joker's stdout) or the value returned by (joker.os/create).
:stderr - the same as :stdout, but for stderr.
Returns a map with the following keys:
:success - whether or not the execution was successful,
:err-msg (present iff :success if false) - string capturing error object returned by Go runtime
:exit - exit code of program (or attempt to execute it),
:out - string capturing stdout of the program (unless :stdout option was passed)
:err - string capturing stderr of the program (unless :stderr option was passed). -
exists?
Function v1.0(exists? path)
Returns true if file or directory with the given path exists. Otherwise returns false.
-
exit
Function v1.0(exit code)
(exit)
Causes the current program to exit with the given status code (defaults to 0).
-
get-env
Function v1.0(get-env key)
Returns the value of the environment variable named by the key or nil if the variable is not present in the environment.
-
ls
Function v1.0(ls dirname)
Reads the directory named by dirname and returns a list of directory entries sorted by filename.
Each entry is a map with the following keys:
:name - name (String)
:size - size in bytes (Int)
:mode - mode (Int)
:dir? - true if the file is a directory (Boolean)
:modtime - modification time (unix timestamp) (Int) -
mkdir
Function v1.0(mkdir name perm)
Creates a new directory with the specified name and permission bits.
-
mkdir-temp
Function v1.0(mkdir-temp dir pattern)
Creates a new temporary directory in the directory dir.
The directory name is generated by taking pattern and applying a random string to the end.
If pattern includes a "*", the random string replaces the last "*".
Returns the name of the new directory. If dir is the empty string,
uses the default directory for temporary files (see joker.os/temp-dir).
Multiple programs calling joker.os/make-temp-dir simultaneously will not choose the same directory.
It is the caller's responsibility to remove the directory when no longer needed. -
open
Function v1.0(open name)
Opens the named file for reading. If successful, the file can be used for reading;
the associated file descriptor has mode O_RDONLY. -
remove
Function v1.0(remove name)
Removes the named file or (empty) directory.
-
remove-all
Function v1.0(remove-all path)
Removes path and any children it contains.
It removes everything it can, then panics with the first error (if
any) it encountered. -
set-env
Function v1.0(set-env key value)
Sets the specified key to the specified value in the environment.
-
sh
Function v1.0(sh name & arguments)
Executes the named program with the given arguments. Returns a map with the following keys:
:success - whether or not the execution was successful,
:err-msg (present iff :success if false) - string capturing error object returned by Go runtime
:exit - exit code of program (or attempt to execute it),
:out - string capturing stdout of the program,
:err - string capturing stderr of the program. -
sh-from
Function v1.0(sh-from dir name & arguments)
Executes the named program with the given arguments and working directory set to dir.
Returns a map with the following keys:
:success - whether or not the execution was successful,
:err-msg (present iff :success if false) - string capturing error object returned by Go runtime
:exit - exit code of program (or attempt to execute it),
:out - string capturing stdout of the program,
:err - string capturing stderr of the program. -
stat
Function v1.0(stat filename)
Returns a map describing the named file. The info map has the following attributes:
:name - base name of the file
:size - length in bytes for regular files; system-dependent for others
:mode - file mode bits
:modtime - modification time
:dir? - true if file is a directory -
temp-dir
Function v1.0(temp-dir)
Returns the default directory to use for temporary files.
On Unix systems, it returns $TMPDIR if non-empty, else /tmp.
On Windows, it uses GetTempPath, returning the first non-empty
value from %TMP%, %TEMP%, %USERPROFILE%, or the Windows directory.
The directory is neither guaranteed to exist nor have accessible permissions.