Skip to content

Commit 1c7dd82

Browse files
Merge pull request #34 from HardCodeDev777/UnityHubCliArgsToOpenCommand
Add UnityHub CLI args to Open command
2 parents bd1fcfc + a04e435 commit 1c7dd82

4 files changed

Lines changed: 37 additions & 2 deletions

File tree

src/ucll/AppConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public static void Build(IConfigurator config)
2222
.WithExample("open")
2323
.WithExample("open", "--favorite")
2424
.WithExample("open", ".")
25+
.WithExample("open", "searchPath", "--no-hub-args", "--", "-batchmode", "-quit")
26+
.WithExample("open", "searchPath", "--no-hub-args")
2527
.WithExample("open", "searchPath", "--code-editor")
2628
.WithExample("open", "searchPath", "--only-code-editor")
2729
.WithExample("open", "searchPath", "--", "-batchmode", "-quit");

src/ucll/Commands/Open/OpenCommand.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ protected override int ExecuteImpl(OpenSettings settings)
66
string searchPath = ResolveSearchPath(settings.SearchPath, settings.Favorite);
77

88
ProjectInfo project = Project.Parse(searchPath);
9-
109
string infoLine = string.Empty;
1110
if (settings.SearchPath != project.Path)
1211
infoLine = "Project: " + project.Path;
@@ -22,6 +21,10 @@ protected override int ExecuteImpl(OpenSettings settings)
2221

2322
string[] additionalArgs = Context.Remaining.Raw.ToArray();
2423
var args = new List<string> { "-projectPath", project.Path };
24+
25+
if (!settings.NoHubArgs)
26+
args.Add(UnityHub.GetProjectArgs(project.Path));
27+
2528
args.AddRange(additionalArgs);
2629

2730
settings.MutatingProcess.Run(

src/ucll/Commands/Open/OpenSettings.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ internal class OpenSettings : MutatingSettings
1010
[Description(Descriptions.Favorite)]
1111
public bool Favorite { get; init; }
1212

13+
[CommandOption("--no-hub-args")]
14+
[Description("Do not use CLI arguments from Unity Hub")]
15+
public bool NoHubArgs { get; init; }
16+
1317
[CommandOption("-c|--code-editor")]
1418
[Description("Open the solution file in the default code editor")]
1519
public bool CodeEditor { get; init; }

src/ucll/Shared/UnityHub.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,32 @@ public IEnumerable<string> GetRecentProjects(bool favoriteOnly = false)
7575
}
7676
}
7777

78+
public string GetProjectArgs(string projectPath)
79+
{
80+
string configDir = platformSupport.UnityHubConfigDirectory;
81+
string argsFile = Path.Combine(configDir, "projectsInfo.json");
82+
83+
try
84+
{
85+
string json = File.ReadAllText(argsFile);
86+
var root = JsonNode.Parse(json);
87+
var project = root?[projectPath]?.AsObject()!;
88+
89+
// The cliArgs field persists even when arguments are removed from a project in Unity Hub,
90+
// but will contain an empty value. Validation is required before use.
91+
string? cliArgs = project["cliArgs"]?.GetValue<string>();
92+
93+
if (!string.IsNullOrEmpty(cliArgs))
94+
return cliArgs;
95+
96+
return string.Empty;
97+
}
98+
catch
99+
{
100+
return string.Empty;
101+
}
102+
}
103+
78104
public void InstallEditorChecked(
79105
string version,
80106
string? changeset,
@@ -187,4 +213,4 @@ private static void WriteStatusUpdate(string message)
187213
// However, we do want the progress feedback that the Hub provides.
188214
AnsiConsole.MarkupLine($"[cyan]{message}...[/]");
189215
}
190-
}
216+
}

0 commit comments

Comments
 (0)