Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vs/
.idea/
vm/

Expand Down
65 changes: 65 additions & 0 deletions src/ucll/Commands/ResetProject/ResetProjectCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
internal class ResetProjectCommand(UnityHub unityHub) : SearchPathCommand<ResetProjectSettings>(unityHub)
{
protected override int ExecuteImpl(ResetProjectSettings settings)
{
string searchPath = ResolveSearchPath(settings.SearchPath, settings.Favorite);
ProjectInfo info = Project.Parse(searchPath);

var resetTargets = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"Assets", "Packages", "ProjectSettings",
};

bool shouldReset = settings.Yes || AnsiConsole.Confirm(
"Do you want to reset this project?",
defaultValue: false);

if (!shouldReset)
{
throw new UserCancelledException("Resetting cancelled.");
}

AnsiConsole.WriteLine();

try
{
foreach (string item in Directory.GetFileSystemEntries(info.Path))
{
string itemName = Path.GetFileName(item);

if (resetTargets.Contains(itemName)) continue;

if (settings.DryRun)
{
AnsiConsole.MarkupLine($"[dim]Would delete: {Markup.Escape(itemName)}[/]");
}
else
{
if (Directory.Exists(item))
{
AnsiConsole.MarkupLine($"[bold]Deleting directory {Markup.Escape(itemName)}...[/]");

Directory.Delete(item, true);

WriteSuccess($"Directory {Markup.Escape(item)} deleted successfully.");
}
else if (File.Exists(item))
{
AnsiConsole.MarkupLine($"[bold]Deleting file {Markup.Escape(itemName)}...[/]");

File.Delete(item);

WriteSuccess($"File {Markup.Escape(itemName)} deleted successfully.");
}
}
}
}
catch (Exception ex)
{
WriteError($"Failed to reset this project: {ex.Message}");
}

WriteSuccess("Resetting process completed.");
return 0;
}
}
12 changes: 12 additions & 0 deletions src/ucll/Commands/ResetProject/ResetProjectSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.ComponentModel;

internal class ResetProjectSettings : MutatingSettings
{
[CommandArgument(0, "[searchPath]")]
[Description(Descriptions.SearchPath)]
public string? SearchPath { get; init; }

[CommandOption("-f|--favorite|--favorites")]
[Description(Descriptions.Favorite)]
public bool Favorite { get; init; }
}
8 changes: 8 additions & 0 deletions src/ucll/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@
.WithExample("uninstall-unused", "--yes")
.WithExample("uninstall-unused", "--dry-run");

config.AddCommand<ResetProjectCommand>("reset-project")
.WithDescription("Reset Unity project by deleting cache files and folders")
.WithExample("reset-project")
.WithExample("reset-project", "--yes")
.WithExample("reset-project", "--dry-run")
.WithExample("reset-project", "--favorite")
.WithExample("reset-project", "searchPath");

config.AddCommand<UpmGitUrlCommand>("upm-git-url")
.WithDescription("Generate a git URL for Unity Package Manager from a Unity project")
.WithExample("upm-git-url")
Expand Down