The modest-config Reference Manual

Next: , Previous: , Up: (dir)   [Contents][Index]

The modest-config Reference Manual

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.

Table of Contents


1 Introduction

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.

Quickstart

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"

Loading modest-config

(ql:quickload :modest-config)

The system only contain the package modest-config, which also has the nickname modest. There are no external dependencies.

API

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.

Locating the config file

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.

License

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


2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 modest-config

A modest config file loader library

Author

Torbjørn Marø <torbjorn.maro@gmail.com>

License

MIT

Source

modest-config.asd.

Child Components

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp   [Contents][Index]

3.1.1 modest-config/modest-config.asd

Source

modest-config.asd.

Parent Component

modest-config (system).

ASDF Systems

modest-config.


3.1.2 modest-config/package.lisp

Source

modest-config.asd.

Parent Component

modest-config (system).

Packages

modest-config.


3.1.3 modest-config/modest-config.lisp

Dependency

package.lisp (file).

Source

modest-config.asd.

Parent Component

modest-config (system).

Public Interface
Internals

4 Packages

Packages are listed by definition order.


Previous: , Up: Packages   [Contents][Index]

4.1 modest-config

Source

package.lisp.

Nickname

modest

Use List

common-lisp.

Public Interface
Internals

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Public Interface


5.1.1 Macros

Macro: with-config (identifier bindings &body body)

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))

Package

modest-config.

Source

modest-config.lisp.


Previous: , Up: Public Interface   [Contents][Index]

5.1.2 Ordinary functions

Function: find-config (&optional identifier)

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.

Package

modest-config.

Source

modest-config.lisp.

Function: load-config (&optional identifier)

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.

Package

modest-config.

Source

modest-config.lisp.


5.2 Internals


Previous: , Up: Internals   [Contents][Index]

5.2.1 Ordinary functions

Function: assert-config-exist (pathname)
Package

modest-config.

Source

modest-config.lisp.

Function: assert-one-exist (pathnames)
Package

modest-config.

Source

modest-config.lisp.

Function: find-by-conventions ()

Will probe for a file in this order: - current-package-name.config - modest.config
- ~/current-package-name.config

Package

modest-config.

Source

modest-config.lisp.

Function: find-by-symbol (symbol)

Will probe for a file in this order (given symbol ’foo or :foo): - FOO.config
- ~/FOO.config

Package

modest-config.

Source

modest-config.lisp.

Function: zip-bindings (map-f bindings)
Package

modest-config.

Source

modest-config.lisp.


Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts


Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables