GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: allow change of config file location via command line args (#112)
Lyze01e06f255066
diff --git a/GlazeWM.Bootstrapper/Program.cs b/GlazeWM.Bootstrapper/Program.csindex e8ebf7ac..2424b32f 100644--- a/GlazeWM.Bootstrapper/Program.cs+++ b/GlazeWM.Bootstrapper/Program.cs@@ -7,9 +7,11 @@ using Microsoft.Extensions.Hosting;using Microsoft.Extensions.Logging;using Microsoft.Extensions.Logging.Console;using System;+using System.Collections.Generic;using System.Diagnostics;using System.Threading;using System.Windows.Forms;+using Microsoft.Extensions.Configuration;namespace GlazeWM.Bootstrapper{@@ -21,7 +23,7 @@ namespace GlazeWM.Bootstrapper/// The main entry point for the application./// </summary>[STAThread]- private static void Main()+ private static void Main(string[] args){Debug.WriteLine("Application started.");@@ -35,7 +37,7 @@ namespace GlazeWM.Bootstrapperreturn;}- var host = CreateHost();+ var host = CreateHost(args);ServiceLocator.Provider = host.Services;var startup = ServiceLocator.Provider.GetRequiredService<Startup>();@@ -43,9 +45,16 @@ namespace GlazeWM.BootstrapperApplication.Run();}- private static IHost CreateHost()+ private static IHost CreateHost(string[] args){return Host.CreateDefaultBuilder()+ .ConfigureAppConfiguration(appConfig =>+ {+ appConfig.AddCommandLine(args, new Dictionary<string, string>+ {+ {"--config", "UserConfigPath"}+ });+ }).ConfigureServices((_, services) =>{services.AddInfrastructureServices();diff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.csindex dd65226c..0fab9f6e 100644--- a/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs+++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs@@ -60,7 +60,7 @@ namespace GlazeWM.Domain.UserConfigs.CommandHandlersprivate static void InitializeSampleUserConfig(string userConfigPath){// Fix any inconsistencies in directory delimiters.- var normalizedUserConfigPath = Path.GetFullPath(new Uri(userConfigPath).LocalPath);+ var normalizedUserConfigPath = new FileInfo(userConfigPath).FullName;var promptResult = MessageBox.Show($"No config file found at {normalizedUserConfigPath}. Create a new config file from the starter template?",diff --git a/GlazeWM.Domain/UserConfigs/UserConfigService.cs b/GlazeWM.Domain/UserConfigs/UserConfigService.csindex daeed323..108c07f7 100644--- a/GlazeWM.Domain/UserConfigs/UserConfigService.cs+++ b/GlazeWM.Domain/UserConfigs/UserConfigService.cs@@ -3,6 +3,7 @@ using System.Collections.Generic;using System.IO;using System.Linq;using GlazeWM.Domain.Windows;+using Microsoft.Extensions.Configuration;namespace GlazeWM.Domain.UserConfigs{@@ -13,11 +14,20 @@ namespace GlazeWM.Domain.UserConfigs/// <summary>/// Path to the user's config file./// </summary>- public string UserConfigPath = Path.Combine(+ public string UserConfigPath => _configuration.GetValue<string>("UserConfigPath") ?? _defaultUserConfigPath;++ private readonly string _defaultUserConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),"./.glaze-wm/config.yaml");+ private readonly IConfiguration _configuration;++ public UserConfigService(IConfiguration configuration)+ {+ _configuration = configuration;+ }+public readonly List<WindowRuleConfig> DefaultWindowRules = GetDefaultWindowRules();private static List<WindowRuleConfig> GetDefaultWindowRules()