public void Parse_ValidArg_SetsConfigFileLocation() { var config = RuntimeConfiguration.Parse(new[] { "app.exe", "--config-file", "test.yaml" }); config.ConfigFileLocation.ShouldBe("test.yaml"); }
/// <summary> /// Loads all required resources. /// </summary> private void Initialise() { // Load compiled-in resources. EmbeddedResources.Load(); Log.Send("------------------------------"); Log.Send($"Starting pass-winmenu {Version}"); Log.Send("------------------------------"); Log.Send($"Enabled security protocols: {ServicePointManager.SecurityProtocol}"); // Create the notification service first, so it's available if initialisation fails. notificationService = Notifications.Create(); // Initialise the DI Container builder. var builder = new ContainerBuilder(); builder.Register(_ => notificationService) .AsImplementedInterfaces() .SingleInstance(); // Now load the configuration options that we'll need // to continue initialising the rest of the applications. var runtimeConfig = RuntimeConfiguration.Parse(Environment.GetCommandLineArgs()); LoadConfigFile(runtimeConfig); builder.Register(_ => ConfigManager.Config).AsSelf(); builder.Register(_ => ConfigManager.Config.Gpg).AsSelf(); builder.Register(_ => ConfigManager.Config.Git).AsSelf(); builder.Register(_ => ConfigManager.Config.PasswordStore).AsSelf(); builder.Register(_ => ConfigManager.Config.Application.UpdateChecking).AsSelf(); builder.Register(_ => ConfigManager.Config.PasswordStore.UsernameDetection).AsSelf(); #if DEBUG Log.EnableFileLogging(); #else if (ConfigManager.Config.CreateLogFile) { Log.EnableFileLogging(); } #endif // Register actions and hotkeys builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(ActionDispatcher))) .InNamespaceOf <ActionDispatcher>() .Except <ActionDispatcher>() .AsImplementedInterfaces(); builder.RegisterType <HotkeyManager>() .AsSelf(); builder.RegisterType <ActionDispatcher>() .WithParameter( (p, ctx) => p.ParameterType == typeof(Dictionary <HotkeyAction, IAction>), (info, context) => context.Resolve <IEnumerable <IAction> >().ToDictionary(a => a.ActionType)); // Register environment wrappers builder.RegisterTypes( typeof(FileSystem), typeof(SystemEnvironment), typeof(Processes), typeof(ExecutablePathResolver) ).AsImplementedInterfaces(); // Register GPG types builder.RegisterTypes( typeof(GpgInstallationFinder), typeof(GpgHomedirResolver), typeof(GpgAgentConfigReader), typeof(GpgAgentConfigUpdater), typeof(GpgTransport), typeof(GpgAgent), typeof(GpgResultVerifier), typeof(GPG) ).AsImplementedInterfaces() .AsSelf(); // Register GPG installation // Single instance, as there is no need to look for the same GPG installation multiple times. builder.Register(context => context.Resolve <GpgInstallationFinder>().FindGpgInstallation(ConfigManager.Config.Gpg.GpgPath)) .SingleInstance(); builder.RegisterType <DialogCreator>() .AsSelf(); // Register the internal password manager builder.Register(context => context.Resolve <IFileSystem>().DirectoryInfo.FromDirectoryName(context.Resolve <PasswordStoreConfig>().Location)) .Named("PasswordStore", typeof(IDirectoryInfo)); builder.RegisterType <GpgRecipientFinder>().WithParameter( (parameter, context) => true, (parameter, context) => context.ResolveNamed <IDirectoryInfo>("PasswordStore")) .AsImplementedInterfaces(); builder.RegisterType <PasswordManager>().WithParameter( (parameter, context) => parameter.ParameterType == typeof(IDirectoryInfo), (parameter, context) => context.ResolveNamed <IDirectoryInfo>("PasswordStore")) .AsImplementedInterfaces() .AsSelf(); builder.RegisterType <PasswordFileParser>().AsSelf(); // Create the Git wrapper, if enabled. // This needs to be a single instance to stop startup warnings being displayed multiple times. builder.RegisterType <GitSyncStrategies>().AsSelf(); builder.Register(CreateSyncService) .AsSelf() .SingleInstance(); builder.Register(context => UpdateCheckerFactory.CreateUpdateChecker(context.Resolve <UpdateCheckingConfig>(), context.Resolve <INotificationService>())); builder.RegisterType <RemoteUpdateCheckerFactory>().AsSelf(); builder.Register(context => context.Resolve <RemoteUpdateCheckerFactory>().Build()).AsSelf(); // Build the container container = builder.Build(); var gpgConfig = container.Resolve <GpgConfig>(); if (gpgConfig.GpgAgent.Config.AllowConfigManagement) { container.Resolve <GpgAgentConfigUpdater>().UpdateAgentConfig(gpgConfig.GpgAgent.Config.Keys); } var actionDispatcher = container.Resolve <ActionDispatcher>(); notificationService.AddMenuActions(actionDispatcher); // Assign our hotkeys. AssignHotkeys(actionDispatcher); // Start checking for updates updateChecker = container.Resolve <UpdateChecker>(); remoteUpdateChecker = container.Resolve <Option <RemoteUpdateChecker> >(); if (container.Resolve <UpdateCheckingConfig>().CheckForUpdates) { updateChecker.Start(); } remoteUpdateChecker.Apply(c => c.Start()); }
public void Parse_NoArgs_ConfigFileLocationIsNull() { var config = RuntimeConfiguration.Parse(new[] { "app.exe" }); config.ConfigFileLocation.ShouldBeNull(); }
public void Parse_MissingArg_ThrowsRuntimeConfigurationError() { Should.Throw <RuntimeConfigurationError>(() => RuntimeConfiguration.Parse(new[] { "app.exe", "--config-file" })); }
public void Parse_InvalidArgs_ThrowsRuntimeConfigurationError() { Should.Throw <RuntimeConfigurationError>(() => RuntimeConfiguration.Parse(new[] { "app.exe", "--not-an-option" })); }