Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ucll/AppConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 4 additions & 1 deletion src/ucll/Commands/Open/OpenCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +21,10 @@ protected override int ExecuteImpl(OpenSettings settings)

string[] additionalArgs = Context.Remaining.Raw.ToArray();
var args = new List<string> { "-projectPath", project.Path };

if (!settings.NoHubArgs)
args.Add(UnityHub.GetProjectArgs(project.Path));

args.AddRange(additionalArgs);

settings.MutatingProcess.Run(
Expand Down
4 changes: 4 additions & 0 deletions src/ucll/Commands/Open/OpenSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
28 changes: 27 additions & 1 deletion src/ucll/Shared/UnityHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,32 @@ public IEnumerable<string> 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<string>();

if (!string.IsNullOrEmpty(cliArgs))
return cliArgs;

return string.Empty;
}
catch
{
return string.Empty;
}
}

public void InstallEditorChecked(
string version,
string? changeset,
Expand Down Expand Up @@ -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}...[/]");
}
}
}