From 7a12e8f66865a5e2f6e41a47a905d2d9d7baffad Mon Sep 17 00:00:00 2001 From: Syping Date: Wed, 19 Nov 2025 18:55:21 +0100 Subject: [PATCH] update create command to use options for jpeg and output --- Commands.cs | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/Commands.cs b/Commands.cs index 3a284cf..148ac2f 100644 --- a/Commands.cs +++ b/Commands.cs @@ -6,7 +6,7 @@ namespace RagePhoto.Cli; internal static class Commands { - internal static void CreateFunction(String format, String jpegFile, String outputFile, String? description, String? json, String? title) { + internal static void CreateFunction(String format, String? jpegFile, String? description, String? json, String? title, String? outputFile) { try { using Photo photo = new(); @@ -23,10 +23,10 @@ internal static class Commands { photo.SetHeader("PHOTO - 10/26/25 02:31:34", 3077307752, 2901366738); } - if (jpegFile == String.Empty) { + if (String.IsNullOrEmpty(jpegFile)) { photo.Jpeg = Properties.Resources.EmptyJpeg; } - else if (jpegFile != null) { + else { using MemoryStream jpegStream = new(); using Stream input = jpegFile == "-" ? Console.OpenStandardInput() : File.OpenRead(jpegFile); input.CopyTo(jpegStream); @@ -49,7 +49,7 @@ internal static class Commands { photo.Description = description ?? String.Empty; photo.Title = title ?? "Custom Photo"; - if (outputFile == "-" || outputFile == String.Empty) { + if (outputFile == "-" || String.IsNullOrEmpty(outputFile)) { using MemoryStream photoStream = new(photo.Save()); using Stream output = Console.OpenStandardOutput(); photoStream.CopyTo(output); @@ -280,13 +280,8 @@ internal static class Commands { formatArgument.CompletionSources.Add(_ => [ new("gta5"), new("rdr2")]); - Argument jpegArgument = new("jpeg") { - Description = "JPEG File", - DefaultValueFactory = _ => "-" - }; - Argument outputArgument = new("output") { - Description = "Output File", - DefaultValueFactory = _ => "-" + Option jpegOption = new("--jpeg", "--image", "-i") { + Description = "JPEG File" }; Option descriptionOption = new("--description", "-d") { Description = "Photo Description" @@ -297,16 +292,19 @@ internal static class Commands { Option titleOption = new("--title", "-t") { Description = "Photo Title" }; + Option outputOption = new("--output", "-o") { + Description = "Output File" + }; Command createCommand = new("create", "Create Photo") { - formatArgument, jpegArgument, outputArgument, descriptionOption, jsonOption, titleOption + formatArgument, jpegOption, descriptionOption, jsonOption, titleOption, outputOption }; createCommand.SetAction(result => CreateFunction( result.GetRequiredValue(formatArgument), - result.GetRequiredValue(jpegArgument), - result.GetRequiredValue(outputArgument), + result.GetValue(jpegOption), result.GetValue(descriptionOption), result.GetValue(jsonOption), - result.GetValue(titleOption))); + result.GetValue(titleOption), + result.GetValue(outputOption))); return createCommand; } }