diff --git a/src/ucll/AppConfiguration.cs b/src/ucll/AppConfiguration.cs index 8576d66..7a01a0d 100644 --- a/src/ucll/AppConfiguration.cs +++ b/src/ucll/AppConfiguration.cs @@ -22,6 +22,8 @@ public static void Build(IConfigurator config) .WithExample("open") .WithExample("open", "--favorite") .WithExample("open", ".") + .WithExample("open", "searchPath", "--no-hub-args", "--", "-batchmode", "-quit") + .WithExample("open", "searchPath", "--no-hub-args") .WithExample("open", "searchPath", "--code-editor") .WithExample("open", "searchPath", "--only-code-editor") .WithExample("open", "searchPath", "--", "-batchmode", "-quit"); diff --git a/src/ucll/Commands/Open/OpenCommand.cs b/src/ucll/Commands/Open/OpenCommand.cs index acc67f6..ed9d338 100644 --- a/src/ucll/Commands/Open/OpenCommand.cs +++ b/src/ucll/Commands/Open/OpenCommand.cs @@ -6,7 +6,6 @@ protected override int ExecuteImpl(OpenSettings settings) string searchPath = ResolveSearchPath(settings.SearchPath, settings.Favorite); ProjectInfo project = Project.Parse(searchPath); - string infoLine = string.Empty; if (settings.SearchPath != project.Path) infoLine = "Project: " + project.Path; @@ -22,6 +21,10 @@ protected override int ExecuteImpl(OpenSettings settings) string[] additionalArgs = Context.Remaining.Raw.ToArray(); var args = new List { "-projectPath", project.Path }; + + if (!settings.NoHubArgs) + args.Add(UnityHub.GetProjectArgs(project.Path)); + args.AddRange(additionalArgs); settings.MutatingProcess.Run( diff --git a/src/ucll/Commands/Open/OpenSettings.cs b/src/ucll/Commands/Open/OpenSettings.cs index 1e9051d..0010b5e 100644 --- a/src/ucll/Commands/Open/OpenSettings.cs +++ b/src/ucll/Commands/Open/OpenSettings.cs @@ -10,6 +10,10 @@ internal class OpenSettings : MutatingSettings [Description(Descriptions.Favorite)] public bool Favorite { get; init; } + [CommandOption("--no-hub-args")] + [Description("Do not use CLI arguments from Unity Hub")] + public bool NoHubArgs { get; init; } + [CommandOption("-c|--code-editor")] [Description("Open the solution file in the default code editor")] public bool CodeEditor { get; init; } diff --git a/src/ucll/Shared/UnityHub.cs b/src/ucll/Shared/UnityHub.cs index 5441a19..fe0db51 100644 --- a/src/ucll/Shared/UnityHub.cs +++ b/src/ucll/Shared/UnityHub.cs @@ -75,6 +75,32 @@ public IEnumerable GetRecentProjects(bool favoriteOnly = false) } } + public string GetProjectArgs(string projectPath) + { + string configDir = platformSupport.UnityHubConfigDirectory; + string argsFile = Path.Combine(configDir, "projectsInfo.json"); + + try + { + string json = File.ReadAllText(argsFile); + var root = JsonNode.Parse(json); + var project = root?[projectPath]?.AsObject()!; + + // The cliArgs field persists even when arguments are removed from a project in Unity Hub, + // but will contain an empty value. Validation is required before use. + string? cliArgs = project["cliArgs"]?.GetValue(); + + if (!string.IsNullOrEmpty(cliArgs)) + return cliArgs; + + return string.Empty; + } + catch + { + return string.Empty; + } + } + public void InstallEditorChecked( string version, string? changeset, @@ -187,4 +213,4 @@ private static void WriteStatusUpdate(string message) // However, we do want the progress feedback that the Hub provides. AnsiConsole.MarkupLine($"[cyan]{message}...[/]"); } -} \ No newline at end of file +}