public void should_use_the_config_file_value() { var args = new string[] { "-config", "TestConfigs/test_config.yaml" }; var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); Assert.AreEqual("~/logDirectoryFromConfigFile", testArgs.Log); }
protected EventStoreHostedService(string[] args) { try { Options = EventStoreOptions.Parse <TOptions>(args, Opts.EnvPrefix, Path.Combine(Locations.DefaultConfigurationDirectory, DefaultFiles.DefaultConfigFile), MutateEffectiveOptions); if (Options.Help) { Console.WriteLine("Options:"); Console.WriteLine(EventStoreOptions.GetUsage <TOptions>()); _skipRun = true; } else if (Options.Version) { Console.WriteLine("EventStore version {0} ({1}/{2}, {3})", VersionInfo.Version, VersionInfo.Branch, VersionInfo.Hashtag, VersionInfo.Timestamp); _skipRun = true; } else { PreInit(Options); Init(Options); Create(Options); } } catch (OptionException exc) { Console.Error.WriteLine("Error while parsing options:"); Console.Error.WriteLine(FormatExceptionMessage(exc)); Console.Error.WriteLine(); Console.Error.WriteLine("Options:"); Console.Error.WriteLine(EventStoreOptions.GetUsage <TOptions>()); throw; } }
public void should_use_the_supplied_argument() { var args = new[] { "--log=~/customLogDirectory" }; var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); Assert.AreEqual("~/customLogDirectory", testArgs.Log); }
public void should_warn_the_user_about_unknown_argument_when_from_config_file() { var args = new string[] { "-config", "TestConfigs/test_config_with_unknown_option.yaml" }; var optionException = Assert.Throws <OptionException>(() => { EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); }); Assert.True(optionException.Message.Contains("UnknownOption")); }
protected ProgramBase(string[] args) { Application.RegisterExitAction(Exit); try { var options = EventStoreOptions.Parse <TOptions>(args, Opts.EnvPrefix, Path.Combine(Locations.DefaultConfigurationDirectory, DefaultFiles.DefaultConfigFile), MutateEffectiveOptions); if (options.Help) { Console.WriteLine("Options:"); Console.WriteLine(EventStoreOptions.GetUsage <TOptions>()); _skipRun = true; } else if (options.Version) { Console.WriteLine("EventStore version {0} ({1}/{2}, {3})", VersionInfo.Version, VersionInfo.Branch, VersionInfo.Hashtag, VersionInfo.Timestamp); _skipRun = true; } else { PreInit(options); Init(options); Create(options); _startupSource.SetResult(true); } } catch (OptionException exc) { Console.Error.WriteLine("Error while parsing options:"); Console.Error.WriteLine(FormatExceptionMessage(exc)); Console.Error.WriteLine(); Console.Error.WriteLine("Options:"); Console.Error.WriteLine(EventStoreOptions.GetUsage <TOptions>()); _startupSource.SetException(exc); } catch (ApplicationInitializationException ex) { var msg = String.Format("Application initialization error: {0}", FormatExceptionMessage(ex)); if (LogManager.Initialized) { Log.FatalException(ex, msg); } else { Console.Error.WriteLine(msg); } _startupSource.SetException(ex); } catch (Exception ex) { var msg = "Unhandled exception while starting application:"; if (LogManager.Initialized) { Log.FatalException(ex, msg); } else { Console.Error.WriteLine(msg); Console.Error.WriteLine(FormatExceptionMessage(ex)); } _startupSource.SetException(ex); } finally { Log.Flush(); } }
public void with_config() { var configFile = HelperExtensions.GetFilePathFromAssembly("TestConfigs/invalid_format_config.yaml"); var args = new string[] { "-config", configFile }; Assert.Throws <OptionException>(() => { EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); }); }
public void should_use_the_defaults() { var args = new string[] { }; var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); Assert.AreEqual("~/logs", testArgs.Log); }
public void should_warn_the_user_about_unknown_argument_when_from_command_line() { var args = new string[] { "-unknown-option", "true" }; var optionException = Assert.Throws <OptionException>(() => { EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); }); Assert.True(optionException.Message.Contains("unknownoption")); }
public void should_use_the_argument_over_the_config_file_value() { var args = new string[] { "-config", "TestConfigs/test_config.yaml", "-log", "~/customLogsDirectory" }; var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); Assert.AreEqual("~/customLogsDirectory", testArgs.Log); }
public void should_use_the_environment_variable_over_the_default_value() { Environment.SetEnvironmentVariable(String.Format("{0}HTTP_PORT", Opts.EnvPrefix), "2111"); var args = new string[] { }; var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); Assert.AreEqual(2111, testArgs.HttpPort); }
public void should_use_the_config_file_value() { var configFile = HelperExtensions.GetFilePathFromAssembly("TestConfigs/test_config.yaml"); var args = new string[] { "-config", configFile }; var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); Assert.AreEqual("~/logDirectoryFromConfigFile", testArgs.Log); }
public void should_inform_the_user_of_the_incorrectly_cased_option() { var args = new string[] { "-config", "TestConfigs/test_config_with_incorrectly_cased_option.yaml" }; var optionException = Assert.Throws <OptionException>(() => { EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); }); Assert.That(optionException.Message.Contains("log should be Log")); Assert.That(optionException.Message.Contains("runProjections should be RunProjections")); }
public void should_use_the_config_value_over_the_environment_variable() { Environment.SetEnvironmentVariable(String.Format("{0}HTTP_PORT", Opts.EnvPrefix), "2111"); var args = new string[] { "-config", "TestConfigs/test_config.yaml" }; var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); Assert.AreEqual(2115, testArgs.HttpPort); }
public void should_be_able_to_parse_the_option_ignoring_casing() { var args = new string[] { "-config", "TestConfigs/test_config_with_incorrectly_cased_option.yaml" }; var options = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); Assert.AreEqual("~/gesLogs", options.Log); Assert.AreEqual(ProjectionType.All, options.RunProjections); }
public void should_not_require_equals_in_method() { var args = new[] { "--log", "./customLogDirectory", "--run-projections", "all" }; var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); Assert.AreEqual("./customLogDirectory", testArgs.Log); Assert.AreEqual(ProjectionType.All, testArgs.RunProjections); }
public void with_environment_variable() { Environment.SetEnvironmentVariable(Opts.EnvPrefix + "HTTP_PORT", "invalid_format"); var args = new string[] { }; Assert.Throws <OptionException>(() => { EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); }); Environment.SetEnvironmentVariable(Opts.EnvPrefix + "HTTP_PORT", null); }
public void should_not_contain_the_unknown_option_in_the_dumping_of_the_options_environment_variable() { Environment.SetEnvironmentVariable(String.Format("{0}UNKNOWN_OPTION", Opts.EnvPrefix), "true"); var args = new string[] { }; EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); Assert.False(EventStoreOptions.DumpOptions().Contains(String.Format("{0}UNKNOWN_OPTION", Opts.EnvPrefix))); }
public void should_use_the_command_line_argument() { Environment.SetEnvironmentVariable(String.Format("{0}HTTP_PORT", Opts.EnvPrefix), "2111"); var args = new string[] { "-config", "TestConfigs/test_config.yaml", "-httpPort", "2115" }; var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); Assert.AreEqual(2115, testArgs.HttpPort); Environment.SetEnvironmentVariable(String.Format("{0}HTTP_PORT", Opts.EnvPrefix), String.Empty); }
public int Run(string[] args) { try { Application.RegisterExitAction(Exit); var options = EventStoreOptions.Parse <TOptions>(args, Opts.EnvPrefix, Path.Combine(Locations.DefaultConfigurationDirectory, DefaultFiles.DefaultConfigFile)); if (options.Help) { Console.WriteLine("Options:"); Console.WriteLine(EventStoreOptions.GetUsage <TOptions>()); } else if (options.Version) { Console.WriteLine("EventStore version {0} ({1}/{2}, {3})", VersionInfo.Version, VersionInfo.Branch, VersionInfo.Hashtag, VersionInfo.Timestamp); Application.ExitSilent(0, "Normal exit."); } else { PreInit(options); Init(options); CommitSuicideIfInBoehmOrOnBadVersionsOfMono(options); Create(options); Start(); _exitEvent.Wait(); } } catch (OptionException exc) { Console.Error.WriteLine("Error while parsing options:"); Console.Error.WriteLine(FormatExceptionMessage(exc)); Console.Error.WriteLine(); Console.Error.WriteLine("Options:"); Console.Error.WriteLine(EventStoreOptions.GetUsage <TOptions>()); } catch (ApplicationInitializationException ex) { Log.FatalException(ex, "Application initialization error: {0}", FormatExceptionMessage(ex)); Application.Exit(ExitCode.Error, FormatExceptionMessage(ex)); } catch (Exception ex) { Console.WriteLine(ex); Log.FatalException(ex, "Unhandled exception while starting application:\n{0}", FormatExceptionMessage(ex)); Application.Exit(ExitCode.Error, FormatExceptionMessage(ex)); } finally { Log.Flush(); } Application.ExitSilent(_exitCode, "Normal exit."); return(_exitCode); }
public void should_be_able_to_parse_the_value_from_a_config_file() { var args = new string[] { "-config", "TestConfigs/test_config.yaml" }; var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); Assert.AreEqual(new IPEndPoint[] { new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1000), new IPEndPoint(IPAddress.Parse("127.0.0.2"), 2000) }, testArgs.GossipSeed); }
public void should_be_able_to_parse_the_value_from_command_line() { var args = new string[] { "-gossip-seed", "127.0.0.1:1000,127.0.0.2:2000" }; var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); Assert.AreEqual(new IPEndPoint[] { new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1000), new IPEndPoint(IPAddress.Parse("127.0.0.2"), 2000) }, testArgs.GossipSeed); }
public void should_be_able_to_parse_the_value_from_an_environment_variable() { Environment.SetEnvironmentVariable(String.Format("{0}GOSSIP_SEED", Opts.EnvPrefix), "127.0.0.1:1000,127.0.0.2:2000"); var args = new string[] {}; var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); Assert.AreEqual(new IPEndPoint[] { new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1000), new IPEndPoint(IPAddress.Parse("127.0.0.2"), 2000) }, testArgs.GossipSeed); }
public void should_use_the_environment_variable_over_the_config_value() { var configFile = HelperExtensions.GetFilePathFromAssembly("TestConfigs/test_config.yaml"); Environment.SetEnvironmentVariable(String.Format("{0}HTTP_PORT", Opts.EnvPrefix), "2111"); var args = new string[] { "-config", configFile }; var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); Assert.AreEqual(2111, testArgs.HttpPort); Environment.SetEnvironmentVariable(String.Format("{0}HTTP_PORT", Opts.EnvPrefix), String.Empty); }
public void should_use_the_command_line_argument() { var configFile = HelperExtensions.GetFilePathFromAssembly("TestConfigs/test_config.yaml"); Environment.SetEnvironmentVariable(String.Format("{0}HTTP_PORT", Opts.EnvPrefix), "2111", EnvironmentVariableTarget.Process); var args = new string[] { "-config", configFile, "-httpPort", "2115" }; var testArgs = EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); Assert.AreEqual(2115, testArgs.HttpPort); Environment.SetEnvironmentVariable(String.Format("{0}HTTP_PORT", Opts.EnvPrefix), null, EnvironmentVariableTarget.Process); }
public void with_command_line_argument() { var args = new string[] { "-httpPort", "invalid_format" }; Assert.Throws <OptionException>(() => { EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); }); }
public void with_config() { var args = new string[] { "-config", "TestConfigs/invalid_format_config.yaml" }; Assert.Throws <OptionException>(() => { EventStoreOptions.Parse <TestArgs>(args, Opts.EnvPrefix); }); }
public TOptions LoadConfig() => EventStoreOptions.Parse <TOptions>(_args, Opts.EnvPrefix, Path.Combine(Locations.DefaultConfigurationDirectory, DefaultFiles.DefaultConfigFile), MutateEffectiveOptions);