Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the modest-config Reference Manual, generated automatically by Declt version 4.0 beta 2 "William Riker" on Mon Aug 15 05:24:24 2022 GMT+0.
Next: Systems, Previous: The modest-config Reference Manual, Up: The modest-config Reference Manual [Contents][Index]
MODEST-CONFIG is a simple configuration file parser for Common Lisp. Config files contain a single Common Lisp property list, and the parser provides a convenient way to extract the properties.
Given a config file:
(
;; This sets property FOO
foo :some-value
;; Here is another property
bar "This is a string"
zot (list 1 2 3 4 5)
;; Config may also contain functions
;; ... if you are willing to trust your config maintainer
quux (lambda (wombat)
(format nil "Hello, ~a" wombat))
)
When you load and extract properties like this:
(with-config "example.config" (zot bar quux)
(format t "The value of zot is ~s~%" zot)
(format t "~a says bar~%" bar)
(format t "(quux \"World\") => ~s~%" (funcall (eval quux) "World")))
Then you get this output:
The value of zot is (1 2 3 4 5)
This is a string says bar
(quux "World") => "Hello, World"
(ql:quickload :modest-config)
The system only contain the package modest-config
, which also has the nickname modest
. There are no external dependencies.
find-config &optional identifier => pathname
load-config &optional identifier => plist
with-config identifier bindings &body body => result, plist
Arguments and values:
identifier -- an object used to identify what config source to use. May be pathname, string, symbol, plist, stream, or nil (details further down).
pathname -- the path to a config file.
plist -- a property list containing the configuration.
bindings -- a list of symbols that will be bound to values from configuration.
body -- forms that will be evaluated in a progn.
result -- the result of evaluating the last expression of body
Note that with-config
also returns the entire configuration property list as it's second value.
Configuration will be loaded based on the following rules:
| Identifier type | What will happen? |
|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| pathname | File designated by pathname is assumed to contain configuration. |
| string | Will be turned into a pathname and handled as such. |
| symbol | If identifier is 'foobar
or :foobar
modest-config will look for a file called foobar.config
, first in the current directory and secondly in the current users home directory. |
| list | Is assumed to be a property list containing the actual configuration. This will fail if passed to find-config
. |
| stream | Config will be read from stream. This will fail if passed to find-config
. |
| null | If the identifier is nil these three locations will be tried is sequence: 1) Package.config in the current directory, where package is the name of the current package. 2) modest.config in the current directory. 3) package.config in the home directory of the current user. |
All functions may invoke an error condition if a configuration file can't be located.
Copyright 2017 Torbjørn Marø
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWAR
Next: Files, Previous: Introduction, Up: The modest-config Reference Manual [Contents][Index]
The main system appears first, followed by any subsystem dependency.
A modest config file loader library
Torbjørn Marø <torbjorn.maro@gmail.com>
MIT
Next: Packages, Previous: Systems, Up: The modest-config Reference Manual [Contents][Index]
Files are sorted by type and then listed depth-first from the systems components trees.
Next: modest-config/package.lisp, Previous: Lisp, Up: Lisp [Contents][Index]
modest-config (system).
Next: modest-config/modest-config.lisp, Previous: modest-config/modest-config.asd, Up: Lisp [Contents][Index]
modest-config (system).
Previous: modest-config/package.lisp, Up: Lisp [Contents][Index]
package.lisp (file).
modest-config (system).
Next: Definitions, Previous: Files, Up: The modest-config Reference Manual [Contents][Index]
Packages are listed by definition order.
modest
common-lisp.
Next: Indexes, Previous: Packages, Up: The modest-config Reference Manual [Contents][Index]
Definitions are sorted by export status, category, package, and then by lexicographic order.
Next: Internals, Previous: Definitions, Up: Definitions [Contents][Index]
Next: Ordinary functions, Previous: Public Interface, Up: Public Interface [Contents][Index]
Example where there exists a file foobar.config that contains a plist
with properties HOST and PORT:
(with-config :foobar (host port)
(format t "Host is ~a~%" host)
(format t "Port is ~a~%" port))
Identifier may be nil to load file based on modest conventions:
(with-config nil (host port)
(format t "Host is ~a~%" host)
(format t "Port is ~a~%" port))
Previous: Macros, Up: Public Interface [Contents][Index]
Finds the config filename based on identifier and some conventions. Identifier may be nil, a symbol, or a filename (with or without path). If config file can’t be found a condition is raised.
Simply reads the first element from config file,
assumed to be a property list, and returns it.
If identifier already is a list, it’s assumed to be the config and
modestly returned.
Previous: Public Interface, Up: Definitions [Contents][Index]
Will probe for a file in this order:
- current-package-name.config
- modest.config
- ~/current-package-name.config
Will probe for a file in this order (given symbol ’foo or :foo):
- FOO.config
- ~/FOO.config
Previous: Definitions, Up: The modest-config Reference Manual [Contents][Index]
Jump to: | A F L M W Z |
---|
Jump to: | A F L M W Z |
---|
Jump to: | F M P S |
---|
Jump to: | F M P S |
---|