NAME
envset - Run command with sets of environment variables
VERSION
This document describes version 0.001 of envset (from Perl distribution App-envset), released on 2017-08-05.
SYNOPSIS
List available environment sets defined in ~/.envsetrc:
% envset
Run a command with the production
set:
% envset production -- myscript.pl --script-opt blah --another-opt
Example ~/.envsetrc:
[production]
DB_HOST=myapp.example.com
DB_NAME=myapp
DB_USER=myapp
DB_PASS=some-long-pazzword
[dev]
DB_HOST=127.0.0.1
DB_NAME=myapp
DB_USER=myapp
DB_PASS=secret123
[debug]
TRACE=1
PERL5OPT=["-d:Confess"] ; enable stack trace
[lg-cs-firenze]
PERL5OPT=["-MLog::ger::Screen::ColorScheme::Firenze"]
[lg-cs-aspirinc]
PERL5OPT=["-MLog::ger::Screen::ColorScheme::AspirinC"]
[lg-cs-unlike]
PERL5OPT=["-MLog::ger::Screen::ColorScheme::Unlike"]
Some more examples of setting environment:
Combine (array values will be joined):
% envset production+lg-cs-unlike -- myscript.pl ...
% envset dev+debug+lg-cs-unlike -- myscript.pl ...
DESCRIPTION
Early release. Some aspects might still change.
TIPS
If you just want a shortcut for frequently used environment variables, you can use shell aliases, e.g.:
alias pg=PAGE_RESULT=1
alias dbg="LOG=1 TRACE=1 PERL5OPT=-MLog::ger::App"
and then:
% pg lcpan mods -n cpan rel
% dbg myapp --arg1 --arg2 val --arg3
is equivalent to:
% PAGE_RESULT=1 lcpan mods -n cpan rel
% LOG=1 TRACE=1 PERLOPT=-MLog::ger::App dbg myapp --arg1 --arg2 val --arg3
envset gives you dedicated configuration files and the ability to add/subtract sets.
OPTIONS
--dump, -d
Instead of running the program, dump the environment variables to be set.
--list, -l
List all available environment variable sets (~ INI sections) in the configuration file.
--variables, -V
Set variable to be used in expression. Expression is a value encoding in IOD which allows you to use some simple expressions to calculate the parameter value, for example:
[section]
DEBUG=1
PERL5OPT=!e "-MLog::ger::Screen::ColorSheme::" . $cs . " -MLog::ger::Output::$out -MSome::Module=debug," . val('DEBUG')
When you run envset with:
% envset -V cs=AspirinC -V out=Screen section --dump
you'll get:
DEBUG=1
PERL5OPT=-MLog::ger::Screen::ColorScheme::AspirinC -MLog::ger::Output::Screen -MSome::Module=debug,1
To refer to other parameters in the configuration file, use:
val('DEBUG')
val('section2.FOO')
To refer to a variable which will be supplied by -V
, use:
$varname
FILES
~/.envsetrc
TODO
Also look at other locations of .envsetrc like /etc/envsetrc, ~/.config/.envsetrc
. Allow multiple -c
.
Document the syntax to subtract/undefine.
Tab completion.
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/App-envset.
SOURCE
Source repository is at https://github.com/perlancar/perl-App-envset.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-envset
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
SEE ALSO
A similar npm package https://www.npmjs.com/package/envset. The usage and configuration syntax is almost identical with the following differences: 1) our startup is a bit better :-) 2) we use IOD for configuration format which is INI with some extra features like merging, specifying array/hash, expressions & variables; 3) we have options like --config-path
.
AUTHOR
perlancar <perlancar@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.