From 2bac205769283d50321952258458d850e681f54a Mon Sep 17 00:00:00 2001 From: Rostislav Kirillov Date: Thu, 18 Jan 2024 04:33:48 +0400 Subject: [PATCH] fix: cleanup commands --- src/SyncFaction.Toolbox/Archiver.cs | 1 - .../Args/AppRootCommand.cs | 1 - src/SyncFaction.Toolbox/Args/Get.cs | 49 ------------------- src/SyncFaction.Toolbox/Args/Pack.cs | 31 ------------ src/SyncFaction.Toolbox/Args/Unpack.cs | 9 ++-- src/SyncFaction.Toolbox/Args/Unpeg.cs | 2 +- 6 files changed, 5 insertions(+), 88 deletions(-) delete mode 100644 src/SyncFaction.Toolbox/Args/Get.cs delete mode 100644 src/SyncFaction.Toolbox/Args/Pack.cs diff --git a/src/SyncFaction.Toolbox/Archiver.cs b/src/SyncFaction.Toolbox/Archiver.cs index 4f99d01..db2a269 100644 --- a/src/SyncFaction.Toolbox/Archiver.cs +++ b/src/SyncFaction.Toolbox/Archiver.cs @@ -88,7 +88,6 @@ public async Task Unpack(UnpackSettings settings, CancellationToken token) foreach (var x in batch.Where(x => !runningTasks.ContainsKey(x))) { runningTasks.Add(x, UnpackArchive(x, cts.Token)); - log.LogDebug("Started new task, running {running}, args {args}", runningTasks.Count, x); } var completed = await Task.WhenAny(runningTasks.Values); var result = await completed; diff --git a/src/SyncFaction.Toolbox/Args/AppRootCommand.cs b/src/SyncFaction.Toolbox/Args/AppRootCommand.cs index 7a44a3a..33de98e 100644 --- a/src/SyncFaction.Toolbox/Args/AppRootCommand.cs +++ b/src/SyncFaction.Toolbox/Args/AppRootCommand.cs @@ -11,7 +11,6 @@ public AppRootCommand() AddCommand(new Unpeg()); AddCommand(new Repeg()); //AddCommand(new Pack()); - AddCommand(new Get()); } public class CommandHandler : ICommandHandler diff --git a/src/SyncFaction.Toolbox/Args/Get.cs b/src/SyncFaction.Toolbox/Args/Get.cs deleted file mode 100644 index dcfe644..0000000 --- a/src/SyncFaction.Toolbox/Args/Get.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.CommandLine; -using System.CommandLine.Hosting; -using System.CommandLine.Invocation; -using System.CommandLine.NamingConventionBinder; -using System.Diagnostics.CodeAnalysis; -using Microsoft.Extensions.DependencyInjection; -using SyncFaction.Toolbox.Models; - -namespace SyncFaction.Toolbox.Args; - -[SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = "Why not?")] -public class Get : Command -{ - private readonly Argument archiveArg = new("archive", "vpp_pc to unpack, globs allowed"); - private readonly Argument fileArg = new("file", "file inside vpp to extract, globs allowed"); - private readonly Argument outputArg = new("output", () => Archiver.DefaultDir, "output path"); - - private readonly Option xmlFormat = new(new[] - { - "-x", - "--xml-format" - }, - "format xml file"); - - private readonly Option force = new(new[] - { - "-f", - "--force" - }, - "overwrite output if exists"); - - public Get() : base(nameof(Get).ToLowerInvariant(), "Extract certain file from vpp_pc to dir") - { - AddArgument(archiveArg); - AddArgument(fileArg); - AddArgument(outputArg); - AddOption(xmlFormat); - AddOption(force); - Handler = CommandHandler.Create(Handle); - } - - private async Task Handle(string archive, string file, string output, bool xmlFormat, bool force, InvocationContext context, CancellationToken token) - { - var settings = new UnpackSettings(archive, file, output, xmlFormat, false, new List(), false, force, 1); - var archiver = context.GetHost().Services.GetRequiredService(); - await archiver.Unpack(settings, token); - return 0; - } -} diff --git a/src/SyncFaction.Toolbox/Args/Pack.cs b/src/SyncFaction.Toolbox/Args/Pack.cs deleted file mode 100644 index 5eddeb2..0000000 --- a/src/SyncFaction.Toolbox/Args/Pack.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.CommandLine; -using System.CommandLine.Invocation; - -namespace SyncFaction.Toolbox.Args; - -public class Pack : Command -{ - public Pack() : base(nameof(Pack).ToLowerInvariant(), "Compress vpp_pc") - { - AddArgument(new Argument("dir", "path to compress")); - AddArgument(new Argument("archive", "vpp_pc output")); - AddOption(new Option(new[] - { - "f", - "force" - }, - "overwrite output if exists")); - } - - public class CommandHandler : ICommandHandler - { - public int Invoke(InvocationContext context) => throw new NotImplementedException(); - - public async Task InvokeAsync(InvocationContext context) - { - throw new NotImplementedException(); - - return 0; - } - } -} diff --git a/src/SyncFaction.Toolbox/Args/Unpack.cs b/src/SyncFaction.Toolbox/Args/Unpack.cs index c3ecf15..9cd4470 100644 --- a/src/SyncFaction.Toolbox/Args/Unpack.cs +++ b/src/SyncFaction.Toolbox/Args/Unpack.cs @@ -11,7 +11,7 @@ namespace SyncFaction.Toolbox.Args; public class Unpack : Command { private readonly Argument archiveArg = new("archive", "vpp or peg archive to unpack, globs allowed"); - private readonly Argument fileArg = new("file", () => "*", "file inside archive to extract, globs allowed"); + private readonly Argument fileArg = new("file", () => "*", "file inside archive to extract, globs allowed. lookup is not recursive!"); private readonly Argument outputArg = new("output", () => Archiver.DefaultDir, "output path"); private readonly Option xmlFormat = new(new[] @@ -33,11 +33,10 @@ public class Unpack : Command "-t", "--textures" }, - () => new List(), $"unpack textures from containers (.cpeg_pc .cvbm_pc .gpeg_pc .gvbm_pc) in {Archiver.DefaultDir} subfolder. Specify one or more supported formats: dds png raw") { ArgumentHelpName = "formats", - AllowMultipleArgumentsPerToken = true + AllowMultipleArgumentsPerToken = true, }; private readonly Option metadata = new(new[] @@ -64,7 +63,7 @@ public class Unpack : Command ArgumentHelpName = "N" }; - public override string? Description => @"Extract archive to dir + public override string? Description => @"Extract archives and containers Supported formats: " + string.Join(" ", Archiver.KnownArchiveExtensions.Concat(Archiver.KnownTextureArchiveExtensions)); public Unpack() : base(nameof(Unpack).ToLowerInvariant()) @@ -89,7 +88,7 @@ private async Task Handle(InvocationContext context, CancellationToken toke var output = context.ParseResult.GetValueForArgument(outputArg); var xmlFormat = context.ParseResult.GetValueForOption(this.xmlFormat); var recursive = context.ParseResult.GetValueForOption(this.recursive); - var textures = context.ParseResult.GetValueForOption(this.textures); + var textures = context.ParseResult.GetValueForOption(this.textures) ?? new List(); var metadata = context.ParseResult.GetValueForOption(this.metadata); var force = context.ParseResult.GetValueForOption(this.force); var parallel = context.ParseResult.GetValueForOption(this.parallel); diff --git a/src/SyncFaction.Toolbox/Args/Unpeg.cs b/src/SyncFaction.Toolbox/Args/Unpeg.cs index ec6676b..3c39b80 100644 --- a/src/SyncFaction.Toolbox/Args/Unpeg.cs +++ b/src/SyncFaction.Toolbox/Args/Unpeg.cs @@ -35,7 +35,7 @@ public class Unpeg : Command }, "overwrite output if exists"); - public Unpeg() : base(nameof(Unpeg).ToLowerInvariant(), "TEST: debug peg info and image conversions") + public Unpeg() : base(nameof(Unpeg).ToLowerInvariant(), "TEST TODO: debug compare dds and png") { AddArgument(pathArg); //AddArgument(outputArg);