Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion src/ucll/Commands/Open/OpenCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ protected override int ExecuteImpl(OpenSettings settings)
string searchPath = ResolveSearchPath(settings.SearchPath, settings.Favorite);

ProjectInfo project = Project.Parse(searchPath);

Comment thread
HardCodeDev777 marked this conversation as resolved.
Outdated
string infoLine = string.Empty;
if (settings.SearchPath != project.Path)
infoLine = "Project: " + project.Path;
Expand All @@ -22,6 +22,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
5 changes: 5 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 All @@ -18,6 +22,7 @@ internal class OpenSettings : MutatingSettings
[Description("Open only the code editor without launching Unity")]
public bool OnlyCodeEditor { get; init; }


Comment thread
HardCodeDev777 marked this conversation as resolved.
Outdated
public override ValidationResult Validate()
{
if (CodeEditor && OnlyCodeEditor)
Expand Down
29 changes: 28 additions & 1 deletion src/ucll/Shared/UnityHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,33 @@ 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()!;

// If you remove args from project in Unity Hub, this field still will exist but now with empty value,
// so we can't guarantee that it has value and we need to check
Comment thread
HardCodeDev777 marked this conversation as resolved.
Outdated
string? cliArgs = project["cliArgs"]?.GetValue<string>();

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

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

Comment thread
HardCodeDev777 marked this conversation as resolved.
Outdated
}

public void InstallEditorChecked(
string version,
string? changeset,
Expand Down Expand Up @@ -187,4 +214,4 @@ private static void WriteStatusUpdate(string message)
// However, we do want the progress feedback that the Hub provides.
AnsiConsole.MarkupLine($"[cyan]{message}...[/]");
}
}
}
Comment thread
chrisyarbrough marked this conversation as resolved.