Skip to content

Commit

Permalink
Verify command
Browse files Browse the repository at this point in the history
  • Loading branch information
b1tcr4sh committed Jan 25, 2023
1 parent 19116a5 commit fd6fc3d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Dbus/DbusClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,14 @@ public static async Task<bool> RemoveModAsync(string profileName, string id, boo

return true;
}
public static async Task<ValidityReport> VerifyAsync(string profileName) {
if (!(await CheckProfileExistsAsync(profileName))) {
throw new Exception($"Profile {profileName} doesn't exist!");
}

IDbusProfile profile = _connection.CreateProxy<IDbusProfile>("org.mercurius.profile", $"/org/mercurius/profile/{profileName}");

return await profile.VerifyAsync();
}
}
}
3 changes: 3 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public static int Main(string[] args) {

branch.AddCommand<List>("list")
.WithDescription("Lists all loaded profiles.");

branch.AddCommand<Verify>("verify")
.WithDescription("Verifies that the profile is useable");
});
config.AddBranch("mod", branch => {
branch.SetDescription("List and remove mods from a specific profile");
Expand Down
47 changes: 47 additions & 0 deletions commands/profile/Verify.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Spectre.Console.Cli;
using Spectre.Console;
using Stargazer.Dbus;

namespace Stargazer.Commands {
public class Verify : AsyncCommand<VerifySettings> {
public override async Task<int> ExecuteAsync(CommandContext context, VerifySettings settings) {
await DbusClient.ConnectAsync();

ValidityReport validity = await DbusClient.VerifyAsync(settings.profile);

AnsiConsole.Write("Verifying {0}...", settings.profile);

if (validity.repaired) {
AnsiConsole.WriteLine("\rVerifying {0} (Passed)", settings.profile);
} else {
AnsiConsole.WriteLine("\rVerifying {0} (Failed)", settings.profile);
}

Mod[] mods = await DbusClient.ListModsAsync(settings.profile);

if (validity.missingDependencies.Length > 0) {
AnsiConsole.WriteLine("Added missing dependencies:");
foreach (string dep in validity.missingDependencies) {
Mod addedDep = mods.Where<Mod>(mod => mod.VersionId.Equals(dep)).First();

AnsiConsole.WriteLine(" {0} / {1}", addedDep.Title, addedDep.ModVersion);
}
}

if (validity.incompatible.Length > 0) {
AnsiConsole.WriteLine("Incompatible mods that were removed:");
foreach (Mod incompatible in validity.incompatible) {
AnsiConsole.WriteLine(" {0} / {1}", incompatible.Title, incompatible.ModVersion);
}
}

return 0;
}
}
public class VerifySettings : CommandSettings {
[CommandArgument(0, "<PROFILE>")]
public string profile { get; set; }
}
}

0 comments on commit fd6fc3d

Please sign in to comment.