ENVASSERT(1p) | User Contributed Perl Documentation | ENVASSERT(1p) |
envassert - Ensure that the environment variables match what you need, or abort.
version 0.010
envassert [options]
Options:
--help
--man
--version
--break-at-error
--env-description
envassert checks that your runtime environment, as defined with environment variables, matches with what you want.
You can define your required environment in a file. Default file is .envassert but you can use any file.
It is advantageous to use envassert for examnple when running a container. If you check your environment for missing or wrongly defined environment variables at the beginning of the container run, your container will fail sooner instead of in a later point in execution when the variables are needed.
There are three kinds of errors:
This error will only be reported if you have set the special option exact. See below.
Environment is described in file .envdesc. Environment description file is a Unix shell compatible file, similar to a .env file.
.envdesc Format
In .envdesc file there is only environment variables, comments or empty rows. Example:
# Required env ## envassert (opts: exact=1) FILENAME=^[[:word:]]{1,}$
Env var name is followed by a regular expression. The regexp is an extended Perl regular expression without quotation marks. One env var and its descriptive regexp use one row.
A comment begins at the beginning of the row and uses the whole row. It start with '#' character.
Two comment characters and the word envassert at the beginning of the row mean this is an envassert meta command. You can specify different environment related options with these commands.
Supported options:
The envassert command is also available as self contained executable. You can download it and run it as it is without additional installation of CPAN packages. Of course, you still need Perl, but Perl comes with any normal Linux installation.
This can be convenient if you want to, for instance, include envassert in a docker container build.
curl -LSs -o envassert https://raw.githubusercontent.com/mikkoi/env-assert/main/envassert.self-contained chmod +x ./envassert
$ envassert Environment Assert: ERRORS: variables: FIRST_VAR: Variable FIRST_VAR is missing from environment FOURTH_VAR: Variable FOURTH_VAR is missing from environment
No external dependencies outside Perl's standard distribution.
Mikko Koivunalho <mikkoi@cpan.org>
This software is copyright (c) 2023 by Mikko Koivunalho.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
2024-01-07 | perl v5.36.0 |