Skip to content

Commit c1ad895

Browse files
Add --only-code-editor flag for open command
1 parent 30b4d2c commit c1ad895

5 files changed

Lines changed: 34 additions & 9 deletions

File tree

TestPlan.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ This document contains test cases that need to be verified before releasing a ne
2525
| Favorites flag alias (--favorite) | `unity open --favorites` | Alias for --favorite | [ ] |
2626
| Open with code editor | `unity open path --code-editor` | Opens project's solution file in default code editor | [ ] |
2727
| Open with code editor (no solution) | `unity open path --code-editor` (not yet generated) | Opens project's solution file as soon as it is generated | [ ] |
28+
| Open only code editor | `unity open path --only-code-editor` | Opens only the code editor without launching Unity | [ ] |
29+
| Code editor flags validation | `unity open path --code-editor --only-code-editor` | Shows error about mutually exclusive flags | [ ] |
2830
| Open with dry-run | `unity open path --dry-run` | Shows what would be executed without opening | [ ] |
2931

3032
### `create`

src/ucll/Commands/Completion/CompletionCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ private static string GenerateZshCompletion()
5151
_arguments \
5252
'(-f --favorite --favorites)'{-f,--favorite,--favorites}'[Use favorite projects only]' \
5353
'(-c --code-editor)'{-c,--code-editor}'[Open the solution file in the default code editor]' \
54+
'(-o --only-code-editor)'{-o,--only-code-editor}'[Open only the code editor without launching Unity]' \
5455
'--dry-run[Show what would be executed without actually running mutating commands]'
5556
;;
5657
create)

src/ucll/Commands/Open/OpenCommand.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,22 @@ protected override int ExecuteImpl(OpenSettings settings)
1313
infoLine += "\nVersion: " + project.VersionAndChangeset;
1414
Debug.WriteLine(infoLine);
1515

16-
UnityHub.InstallEditorChecked(project.Version, project.Changeset, settings.MutatingProcess);
16+
if (!settings.OnlyCodeEditor)
17+
{
18+
UnityHub.InstallEditorChecked(project.Version, project.Changeset, settings.MutatingProcess);
1719

18-
string editorPath = UnityHub.GetEditorPath(project.Version);
19-
AnsiConsole.MarkupLine($"[dim]Editor: {editorPath}[/]");
20+
string editorPath = UnityHub.GetEditorPath(project.Version);
21+
AnsiConsole.MarkupLine($"[dim]Editor: {editorPath}[/]");
2022

21-
string[] additionalArgs = Context.Remaining.Raw.ToArray();
22-
var args = new List<string> { "-projectPath", project.Path };
23-
args.AddRange(additionalArgs);
23+
string[] additionalArgs = Context.Remaining.Raw.ToArray();
24+
var args = new List<string> { "-projectPath", project.Path };
25+
args.AddRange(additionalArgs);
2426

25-
settings.MutatingProcess.Run(
26-
new ProcessStartInfo(fileName: editorPath, arguments: ProcessRunner.JoinQuoted(args)));
27+
settings.MutatingProcess.Run(
28+
new ProcessStartInfo(fileName: editorPath, arguments: ProcessRunner.JoinQuoted(args)));
29+
}
2730

28-
if (settings.CodeEditor)
31+
if (settings.CodeEditor || settings.OnlyCodeEditor)
2932
{
3033
OpenSolutionFile(project.Path, settings.MutatingProcess);
3134
}

src/ucll/Commands/Open/OpenSettings.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,21 @@ internal class OpenSettings : MutatingSettings
1313
[CommandOption("-c|--code-editor")]
1414
[Description("Open the solution file in the default code editor")]
1515
public bool CodeEditor { get; init; }
16+
17+
[CommandOption("-o|--only-code-editor")]
18+
[Description("Open only the code editor without launching Unity")]
19+
public bool OnlyCodeEditor { get; init; }
20+
21+
public override ValidationResult Validate()
22+
{
23+
if (CodeEditor && OnlyCodeEditor)
24+
{
25+
return ValidationResult.Error(
26+
"Cannot use both --code-editor and --only-code-editor. " +
27+
"Use --code-editor to open both Unity and the code editor, " +
28+
"or --only-code-editor to open only the code editor.");
29+
}
30+
31+
return base.Validate();
32+
}
1633
}

src/ucll/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
config.SetApplicationVersion("0.2.0");
1818
config.AddExample("open");
1919
config.AddExample("open", "searchPath", "--code-editor");
20+
config.AddExample("open", "searchPath", "--only-code-editor");
2021
config.AddExample("open", "searchPath", "--", "-batchmode", "-quit");
2122

2223
config.AddCommand<OpenCommand>("open")
@@ -25,6 +26,7 @@
2526
.WithExample("open", "--favorite")
2627
.WithExample("open", ".")
2728
.WithExample("open", "searchPath", "--code-editor")
29+
.WithExample("open", "searchPath", "--only-code-editor")
2830
.WithExample("open", "searchPath", "--", "-batchmode", "-quit");
2931

3032
config.AddCommand<CreateCommand>("create")

0 commit comments

Comments
 (0)