Class Environment


  • public final class Environment
    extends Object
    The environment variables for CLI commands. An instance of this class is passed to each command to give it access to environment variables. Command implementations should access environment information from this class rather than using System.getenv. In multimode, the export command may change environment variables in the instance of this class that is shared by all commands.
    Author:
    Bill Shannon
    • Constructor Detail

      • Environment

        public Environment()
        Initialise the environment with all relevant system environment entries.
      • Environment

        public Environment​(boolean ignoreEnvironment)
        Initialise the environment with all relevant entries
        Parameters:
        ignoreEnvironment - true for constructor that ignores the system environment, mostly used to enable repeatable tests.
    • Method Detail

      • setPrefix

        public static void setPrefix​(String p)
        Set the prefix for environment variables referenced from the system environment by Environment objects.
        Parameters:
        p - the new prefix
      • getPrefix

        public static String getPrefix()
        Get the prefix for environment variables referenced from the system environment by Environment objects.
        Returns:
      • setShortPrefix

        public static void setShortPrefix​(String p)
        Set the short prefix for environment variables referenced from the system environment by Environment objects. This effects methods such as debug(), trace(), etc.
        Parameters:
        p -
      • getDebugVar

        public static String getDebugVar()
        Get the name of the environment variable used to set debugging on
        Returns:
      • getBooleanOption

        public boolean getBooleanOption​(String name)
        Return the value of the environment entry corresponding to the named option.
        Parameters:
        name - the option name
        Returns:
        the value of the corresponding environment entry
      • getStringOption

        public String getStringOption​(String name)
        Return the value of the environment entry corresponding to the named option.
        Parameters:
        name - the option name
        Returns:
        the value of the corresponding environment entry
      • hasOption

        public boolean hasOption​(String name)
        Is there an environment entry corresponding to the named option?
        Parameters:
        name - the option name
        Returns:
        true if there's a corresponding environment entry
      • get

        public String get​(String name)
        Get the named environment entry.
        Parameters:
        name - the name of the environment entry
        Returns:
        the value of the entry, or null if no such entry
      • put

        public String put​(String name,
                          String value)
        Set the named environment entry to the specified value.
        Parameters:
        name - the environment entry name
        value - the value
        Returns:
        the previous value of the entry
      • remove

        public void remove​(String name)
        Remove the name environment entry.
        Parameters:
        name - the environment entry name
      • putOption

        public String putOption​(String name,
                                String value)
        Set the environment entry corresponding to the named option to the specified value.
        Parameters:
        name - the option name
        value - the value
        Returns:
        the previous value of the entry
      • entrySet

        public Set<Map.Entry<String,​String>> entrySet()
        Return a set of all the entries, just like a Map does.
        Returns:
      • debug

        public boolean debug()
      • trace

        public boolean trace()
      • getDebugLogfile

        public File getDebugLogfile()