envir/vars.fz
# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation. If not, see <https://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------
#
# Tokiwa Software GmbH, Germany
#
# Source code of Fuzion standard library feature envir.vars
#
# Author: Fridtjof Siebert (siebert@tokiwa.software)
#
# -----------------------------------------------------------------------
# envir.vars -- effect providing access to environment variables
#
public vars (p Vars_Handler) : simple_effect is
# If set, get the environment variable corresponding to v.
#
public get(v String) =>
vars.this.env.replace
p.get v
# If set, get the environment variable corresponding to v.
# Otherwise, return default
#
public get(v String, default String) =>
(get v).get get.this.default
# Set the environment variable corresponding to n to have the
# value v.
#
# This will overwrite the value of the environment variable, if
# it is set already.
public set1(n String, v String) =>
vars.this.env.replace
p.set1 n v
# Unset the environment variable corresponding to n.
#
# This will also return success (unit) if the variable was not
# set anyway.
public unset(n String) =>
vars.this.env.replace
p.unset n
# install default instance of vars
#
type.install_default =>
(envir.vars default_vars_handler).default
# default handler using fuzion.sys.env_vars
#
type.default_vars_handler : envir.Vars_Handler is
get(v String) => fuzion.sys.env_vars.get v
set1(n String, v String) => fuzion.sys.env_vars.set1 n v
unset(n String) => fuzion.sys.env_vars.unset n
# short-hand for accessing envir.args effect in current environment
#
public vars =>
vars.install_default
envir.vars.env
# Vars_Handler -- abstract source of environment vars
#
# Different heirs of this feature may provided different sources for environment
# variables
#
private:public Vars_Handler ref is
# If set, get the environment variable corresponding to v
#
get(v String) option String => abstract
# Set the environment variable corresponding to n to have the
# value v.
#
# This will overwrite the value of the environment variable, if
# it is set already.
set1(n String, v String) outcome unit => abstract
# Unset the environment variable corresponding to n.
#
# This will also return success (unit) if the variable was not
# set anyway.
unset(n String) outcome unit => abstract
last changed: 2024-03-07