From c131a7532ef26d7ed1fc692992e51308f8968a5b Mon Sep 17 00:00:00 2001 From: Syping Date: Sun, 23 Nov 2025 06:13:24 +0100 Subject: [PATCH] image-as-is option and error messages improvements - order image-as-is option at the end and improve it's description - display errors on console with red color --- Commands.cs | 52 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/Commands.cs b/Commands.cs index e68ccbd..63dd3ff 100644 --- a/Commands.cs +++ b/Commands.cs @@ -5,8 +5,8 @@ namespace RagePhoto.Cli; internal static partial class Commands { - internal static Int32 CreateFunction(String format, String? imageFile, bool imageAsIs, - String? description, String? json, String? title, String? outputFile) { + internal static Int32 CreateFunction(String format, String? imageFile, String? description, + String? json, String? title, String? outputFile, bool imageAsIs) { try { using Photo photo = new(); @@ -62,15 +62,21 @@ internal static partial class Commands { return 0; } catch (RagePhotoException exception) { + Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine(exception.Message); + Console.ResetColor(); return exception.Photo != null ? (Int32)exception.Error + 2 : -1; } catch (ArgumentException exception) { + Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine(exception.Message); + Console.ResetColor(); return 1; } catch (Exception exception) { + Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine(exception.Message); + Console.ResetColor(); return -1; } } @@ -139,17 +145,21 @@ internal static partial class Commands { return 0; } catch (RagePhotoException exception) { + Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine(exception.Message); + Console.ResetColor(); return exception.Photo != null ? (Int32)exception.Error + 2 : -1; } catch (Exception exception) { + Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine(exception.Message); + Console.ResetColor(); return -1; } } - internal static Int32 SetFunction(String inputFile, String? format, String? imageFile, bool imageAsIs, - String? description, String? json, String? title, bool updateJson, String? outputFile) { + internal static Int32 SetFunction(String inputFile, String? format, String? imageFile, String? description, + String? json, String? title, bool updateJson, String? outputFile, bool imageAsIs) { try { if (format == null && imageFile == null && description == null && json == null && title == null && !updateJson) { @@ -215,15 +225,21 @@ internal static partial class Commands { return 0; } catch (RagePhotoException exception) { + Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine(exception.Message); + Console.ResetColor(); return exception.Photo != null ? (Int32)exception.Error + 2 : -1; } catch (ArgumentException exception) { + Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine(exception.Message); + Console.ResetColor(); return 1; } catch (Exception exception) { + Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine(exception.Message); + Console.ResetColor(); return -1; } } @@ -245,9 +261,6 @@ internal static partial class Commands { Option imageOption = new("--image", "-i", "--jpeg") { Description = "Image File" }; - Option imageAsIsOption = new("--image-as-is") { - Description = "Image as-is" - }; Option descriptionOption = new("--description", "-d") { Description = "Description" }; @@ -260,23 +273,26 @@ internal static partial class Commands { Option outputOption = new("--output", "-o") { Description = "Output File" }; + Option imageAsIsOption = new("--image-as-is") { + Description = "Force image being set as-is" + }; Command createCommand = new("create", "Create a new Photo") { formatArgument, imageOption, - imageAsIsOption, descriptionOption, jsonOption, titleOption, - outputOption + outputOption, + imageAsIsOption }; createCommand.SetAction(result => Environment.ExitCode = CreateFunction( result.GetRequiredValue(formatArgument), result.GetValue(imageOption), - result.GetValue(imageAsIsOption), result.GetValue(descriptionOption), result.GetValue(jsonOption), result.GetValue(titleOption), - result.GetValue(outputOption))); + result.GetValue(outputOption), + result.GetValue(imageAsIsOption))); return createCommand; } } @@ -337,9 +353,6 @@ internal static partial class Commands { Option imageOption = new("--image", "-i", "--jpeg") { Description = "Image File" }; - Option imageAsIsOption = new("--image-as-is") { - Description = "Image as-is" - }; Option descriptionOption = new("--description", "-d") { Description = "Description" }; @@ -355,27 +368,30 @@ internal static partial class Commands { Option outputOption = new("--output", "-o") { Description = "Output File" }; + Option imageAsIsOption = new("--image-as-is") { + Description = "Force image being set as-is" + }; Command setCommand = new("set", "Set Data from a Photo") { inputArgument, formatOption, imageOption, - imageAsIsOption, descriptionOption, jsonOption, titleOption, updateJsonOption, - outputOption + outputOption, + imageAsIsOption }; setCommand.SetAction(result => Environment.ExitCode = SetFunction( result.GetRequiredValue(inputArgument), result.GetValue(formatOption), result.GetValue(imageOption), - result.GetValue(imageAsIsOption), result.GetValue(descriptionOption), result.GetValue(jsonOption), result.GetValue(titleOption), result.GetValue(updateJsonOption), - result.GetValue(outputOption))); + result.GetValue(outputOption), + result.GetValue(imageAsIsOption))); return setCommand; } }