The modest-config Reference Manual

Table of Contents

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

The modest-config Reference Manual

This is the modest-config Reference Manual, generated automatically by Declt version 2.3 "Robert April" on Tue Feb 20 09:05:27 2018 GMT+0.


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

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


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

2 Systems

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


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

2.1 modest-config

Author

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

License

MIT

Description

A modest config file loader library

Source

modest-config.asd (file)

Components

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

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 files   [Contents][Index]

3.1.1 modest-config.asd

Location

modest-config.asd

Systems

modest-config (system)


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

3.1.2 modest-config/package.lisp

Parent

modest-config (system)

Location

package.lisp

Packages

modest-config


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

3.1.3 modest-config/modest-config.lisp

Dependency

package.lisp (file)

Parent

modest-config (system)

Location

modest-config.lisp

Exported Definitions
Internal Definitions

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

4 Packages

Packages are listed by definition order.


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

4.1 modest-config

Source

package.lisp (file)

Nickname

modest

Use List

common-lisp

Exported Definitions
Internal Definitions

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

5 Definitions

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


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

5.1 Exported definitions


Next: , Previous: , Up: Exported definitions   [Contents][Index]

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


Previous: , Up: Exported definitions   [Contents][Index]

5.1.2 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 (file)

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


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

5.2 Internal definitions


Previous: , Up: Internal definitions   [Contents][Index]

5.2.1 Functions

Function: assert-config-exist PATHNAME
Package

modest-config

Source

modest-config.lisp (file)

Function: assert-one-exist PATHNAMES
Package

modest-config

Source

modest-config.lisp (file)

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

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

Function: zip-bindings MAP-F BINDINGS
Package

modest-config

Source

modest-config.lisp (file)


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

Appendix A Indexes


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

A.1 Concepts

Jump to:   F   L   M  
Index Entry  Section

F
File, Lisp, modest-config.asd: The modest-config<dot>asd file
File, Lisp, modest-config/modest-config.lisp: The modest-config/modest-config<dot>lisp file
File, Lisp, modest-config/package.lisp: The modest-config/package<dot>lisp file

L
Lisp File, modest-config.asd: The modest-config<dot>asd file
Lisp File, modest-config/modest-config.lisp: The modest-config/modest-config<dot>lisp file
Lisp File, modest-config/package.lisp: The modest-config/package<dot>lisp file

M
modest-config.asd: The modest-config<dot>asd file
modest-config/modest-config.lisp: The modest-config/modest-config<dot>lisp file
modest-config/package.lisp: The modest-config/package<dot>lisp file

Jump to:   F   L   M  

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

A.2 Functions

Jump to:   A   F   L   M   W   Z  
Index Entry  Section

A
assert-config-exist: Internal functions
assert-one-exist: Internal functions

F
find-by-conventions: Internal functions
find-by-symbol: Internal functions
find-config: Exported functions
Function, assert-config-exist: Internal functions
Function, assert-one-exist: Internal functions
Function, find-by-conventions: Internal functions
Function, find-by-symbol: Internal functions
Function, find-config: Exported functions
Function, load-config: Exported functions
Function, zip-bindings: Internal functions

L
load-config: Exported functions

M
Macro, with-config: Exported macros

W
with-config: Exported macros

Z
zip-bindings: Internal functions

Jump to:   A   F   L   M   W   Z  

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

A.3 Variables


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

A.4 Data types

Jump to:   M   P   S  
Index Entry  Section

M
modest-config: The modest-config system
modest-config: The modest-config package

P
Package, modest-config: The modest-config package

S
System, modest-config: The modest-config system

Jump to:   M   P   S