In many situations it is useful to be able to import a bag of files as an object. For instance, it is convenient to
load all environment configuration files present with a single invocation to import
to pick up all files found without
having to name them individually.
For this purpose, qbec supplies a glob importer for importing a bag of files using a glob pattern. It supports two variants, one for importing the files that match the glob as code and another for importing the files as a string (suitable, for example, for YAML files).
The basic syntax is:
import 'glob-import:subdir/*.libsonnet' // imports all libsonnet files from the subdirectory
and
import 'glob-importstr:*.yaml' // imports all YAML files in the current directory as strings
Let’s say that in the first example you had files a.libsonnet
, b.libsonnet
and c.libsonnet
in subdir/
.
This would result in the following code being evaluated by jsonnet.
{
'subdir/a.libsonnet': import 'subdir/a.libsonnet',
'subdir/b.libsonnet': import 'subdir/b.libsonnet',
'subdir/c.libsonnet': import 'subdir/c.libsonnet',
}
In the second example if you had a.yaml
, b.yaml
and c.yaml
in the current directory, the following code
would be evaluated:
{
'a.yaml': importstr 'a.yaml',
'b.yaml': importstr 'b.yaml',
'c.yaml': importstr 'c.yaml',
}
In both cases, the keys are paths to files relative to the directory where the import
was invoked, and the objects
are the objects as returned by the jsonnet import
and importstr
directives respectively.
*.libsonnet
means
when there are libsonnet files in the current directory as well as in the library paths.