Ejemplo n.º 1
0
        public static Option <bool, Error> LoadEnvironmentVariables(IEnvironment environment, string configFilePath, IEnumerable <string> envFiles)
        {
            if (environment == null)
            {
                throw new ArgumentNullException(nameof(environment));
            }
            if (configFilePath == null)
            {
                throw new ArgumentNullException(nameof(configFilePath));
            }

            var defaultEnvFile = Path.Combine(environment.GetCurrentDirectory(), Constants.Default.DotEnvFileName);

            if (environment.FileExists(defaultEnvFile))
            {
                DotNetEnv.Env.Load(defaultEnvFile);
            }

            var configFileEnv = Path.Combine(new FileInfo(configFilePath).DirectoryName, Constants.Default.DotEnvFileName);

            if (environment.FileExists(configFileEnv))
            {
                DotNetEnv.Env.Load(configFileEnv);
            }

            if (envFiles != null)
            {
                foreach (var file in envFiles)
                {
                    Error error = null;
                    ConfigLoader.GetFilePath(environment, file)
                    .Match(
                        some: path => DotNetEnv.Env.Load(path),
                        none: err => error = err);

                    if (error != null)
                    {
                        return(Option.None <bool, Error>(error));
                    }
                }
            }

            return(true.Some <bool, Error>());
        }
Ejemplo n.º 2
0
 private Option <int, Error> RunStatusCommand(StatusOptions opts) =>
 ConfigurationHelper.LoadEnvironmentVariables(Environment, opts.File, opts.EnvFiles)
 .Match(
     some: _ => ConfigLoader.LoadMigration(ConfigLoader.GetFilePath(Environment, opts.File))
     .Match(
         some: x =>
         ConfigurationHelper
         .SelectDbProvider(x.Provider, x.ConnectionString, x.ConnectionTimeoutSec)
         .SelectJournal(x.JournalTo)
         .SelectTransaction(x.Transaction)
         .SelectLogOptions(Logger, VerbosityLevel.Min)
         .SelectScripts(x.Scripts)
         .AddVariables(x.Vars)
         .OverrideConnectionFactory(ConnectionFactory)
         .Match(
             some: builder =>
 {
     var engine = builder.Build();
     if (!engine.TryConnect(out var message))
     {
         return(Option.None <int, Error>(Error.Create(message)));