mirror of
https://github.com/Syping/ragephoto-cli.git
synced 2025-12-04 16:51:48 +01:00
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
This commit is contained in:
parent
5395f8ee2e
commit
c131a7532e
1 changed files with 34 additions and 18 deletions
52
Commands.cs
52
Commands.cs
|
|
@ -5,8 +5,8 @@ namespace RagePhoto.Cli;
|
||||||
|
|
||||||
internal static partial class Commands {
|
internal static partial class Commands {
|
||||||
|
|
||||||
internal static Int32 CreateFunction(String format, String? imageFile, bool imageAsIs,
|
internal static Int32 CreateFunction(String format, String? imageFile, String? description,
|
||||||
String? description, String? json, String? title, String? outputFile) {
|
String? json, String? title, String? outputFile, bool imageAsIs) {
|
||||||
try {
|
try {
|
||||||
using Photo photo = new();
|
using Photo photo = new();
|
||||||
|
|
||||||
|
|
@ -62,15 +62,21 @@ internal static partial class Commands {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch (RagePhotoException exception) {
|
catch (RagePhotoException exception) {
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.Error.WriteLine(exception.Message);
|
Console.Error.WriteLine(exception.Message);
|
||||||
|
Console.ResetColor();
|
||||||
return exception.Photo != null ? (Int32)exception.Error + 2 : -1;
|
return exception.Photo != null ? (Int32)exception.Error + 2 : -1;
|
||||||
}
|
}
|
||||||
catch (ArgumentException exception) {
|
catch (ArgumentException exception) {
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.Error.WriteLine(exception.Message);
|
Console.Error.WriteLine(exception.Message);
|
||||||
|
Console.ResetColor();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
catch (Exception exception) {
|
catch (Exception exception) {
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.Error.WriteLine(exception.Message);
|
Console.Error.WriteLine(exception.Message);
|
||||||
|
Console.ResetColor();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -139,17 +145,21 @@ internal static partial class Commands {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch (RagePhotoException exception) {
|
catch (RagePhotoException exception) {
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.Error.WriteLine(exception.Message);
|
Console.Error.WriteLine(exception.Message);
|
||||||
|
Console.ResetColor();
|
||||||
return exception.Photo != null ? (Int32)exception.Error + 2 : -1;
|
return exception.Photo != null ? (Int32)exception.Error + 2 : -1;
|
||||||
}
|
}
|
||||||
catch (Exception exception) {
|
catch (Exception exception) {
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.Error.WriteLine(exception.Message);
|
Console.Error.WriteLine(exception.Message);
|
||||||
|
Console.ResetColor();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static Int32 SetFunction(String inputFile, String? format, String? imageFile, bool imageAsIs,
|
internal static Int32 SetFunction(String inputFile, String? format, String? imageFile, String? description,
|
||||||
String? description, String? json, String? title, bool updateJson, String? outputFile) {
|
String? json, String? title, bool updateJson, String? outputFile, bool imageAsIs) {
|
||||||
try {
|
try {
|
||||||
if (format == null && imageFile == null && description == null
|
if (format == null && imageFile == null && description == null
|
||||||
&& json == null && title == null && !updateJson) {
|
&& json == null && title == null && !updateJson) {
|
||||||
|
|
@ -215,15 +225,21 @@ internal static partial class Commands {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch (RagePhotoException exception) {
|
catch (RagePhotoException exception) {
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.Error.WriteLine(exception.Message);
|
Console.Error.WriteLine(exception.Message);
|
||||||
|
Console.ResetColor();
|
||||||
return exception.Photo != null ? (Int32)exception.Error + 2 : -1;
|
return exception.Photo != null ? (Int32)exception.Error + 2 : -1;
|
||||||
}
|
}
|
||||||
catch (ArgumentException exception) {
|
catch (ArgumentException exception) {
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.Error.WriteLine(exception.Message);
|
Console.Error.WriteLine(exception.Message);
|
||||||
|
Console.ResetColor();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
catch (Exception exception) {
|
catch (Exception exception) {
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.Error.WriteLine(exception.Message);
|
Console.Error.WriteLine(exception.Message);
|
||||||
|
Console.ResetColor();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -245,9 +261,6 @@ internal static partial class Commands {
|
||||||
Option<String?> imageOption = new("--image", "-i", "--jpeg") {
|
Option<String?> imageOption = new("--image", "-i", "--jpeg") {
|
||||||
Description = "Image File"
|
Description = "Image File"
|
||||||
};
|
};
|
||||||
Option<bool> imageAsIsOption = new("--image-as-is") {
|
|
||||||
Description = "Image as-is"
|
|
||||||
};
|
|
||||||
Option<String?> descriptionOption = new("--description", "-d") {
|
Option<String?> descriptionOption = new("--description", "-d") {
|
||||||
Description = "Description"
|
Description = "Description"
|
||||||
};
|
};
|
||||||
|
|
@ -260,23 +273,26 @@ internal static partial class Commands {
|
||||||
Option<String?> outputOption = new("--output", "-o") {
|
Option<String?> outputOption = new("--output", "-o") {
|
||||||
Description = "Output File"
|
Description = "Output File"
|
||||||
};
|
};
|
||||||
|
Option<bool> imageAsIsOption = new("--image-as-is") {
|
||||||
|
Description = "Force image being set as-is"
|
||||||
|
};
|
||||||
Command createCommand = new("create", "Create a new Photo") {
|
Command createCommand = new("create", "Create a new Photo") {
|
||||||
formatArgument,
|
formatArgument,
|
||||||
imageOption,
|
imageOption,
|
||||||
imageAsIsOption,
|
|
||||||
descriptionOption,
|
descriptionOption,
|
||||||
jsonOption,
|
jsonOption,
|
||||||
titleOption,
|
titleOption,
|
||||||
outputOption
|
outputOption,
|
||||||
|
imageAsIsOption
|
||||||
};
|
};
|
||||||
createCommand.SetAction(result => Environment.ExitCode = CreateFunction(
|
createCommand.SetAction(result => Environment.ExitCode = CreateFunction(
|
||||||
result.GetRequiredValue(formatArgument),
|
result.GetRequiredValue(formatArgument),
|
||||||
result.GetValue(imageOption),
|
result.GetValue(imageOption),
|
||||||
result.GetValue(imageAsIsOption),
|
|
||||||
result.GetValue(descriptionOption),
|
result.GetValue(descriptionOption),
|
||||||
result.GetValue(jsonOption),
|
result.GetValue(jsonOption),
|
||||||
result.GetValue(titleOption),
|
result.GetValue(titleOption),
|
||||||
result.GetValue(outputOption)));
|
result.GetValue(outputOption),
|
||||||
|
result.GetValue(imageAsIsOption)));
|
||||||
return createCommand;
|
return createCommand;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -337,9 +353,6 @@ internal static partial class Commands {
|
||||||
Option<String?> imageOption = new("--image", "-i", "--jpeg") {
|
Option<String?> imageOption = new("--image", "-i", "--jpeg") {
|
||||||
Description = "Image File"
|
Description = "Image File"
|
||||||
};
|
};
|
||||||
Option<bool> imageAsIsOption = new("--image-as-is") {
|
|
||||||
Description = "Image as-is"
|
|
||||||
};
|
|
||||||
Option<String?> descriptionOption = new("--description", "-d") {
|
Option<String?> descriptionOption = new("--description", "-d") {
|
||||||
Description = "Description"
|
Description = "Description"
|
||||||
};
|
};
|
||||||
|
|
@ -355,27 +368,30 @@ internal static partial class Commands {
|
||||||
Option<String?> outputOption = new("--output", "-o") {
|
Option<String?> outputOption = new("--output", "-o") {
|
||||||
Description = "Output File"
|
Description = "Output File"
|
||||||
};
|
};
|
||||||
|
Option<bool> imageAsIsOption = new("--image-as-is") {
|
||||||
|
Description = "Force image being set as-is"
|
||||||
|
};
|
||||||
Command setCommand = new("set", "Set Data from a Photo") {
|
Command setCommand = new("set", "Set Data from a Photo") {
|
||||||
inputArgument,
|
inputArgument,
|
||||||
formatOption,
|
formatOption,
|
||||||
imageOption,
|
imageOption,
|
||||||
imageAsIsOption,
|
|
||||||
descriptionOption,
|
descriptionOption,
|
||||||
jsonOption,
|
jsonOption,
|
||||||
titleOption,
|
titleOption,
|
||||||
updateJsonOption,
|
updateJsonOption,
|
||||||
outputOption
|
outputOption,
|
||||||
|
imageAsIsOption
|
||||||
};
|
};
|
||||||
setCommand.SetAction(result => Environment.ExitCode = SetFunction(
|
setCommand.SetAction(result => Environment.ExitCode = SetFunction(
|
||||||
result.GetRequiredValue(inputArgument),
|
result.GetRequiredValue(inputArgument),
|
||||||
result.GetValue(formatOption),
|
result.GetValue(formatOption),
|
||||||
result.GetValue(imageOption),
|
result.GetValue(imageOption),
|
||||||
result.GetValue(imageAsIsOption),
|
|
||||||
result.GetValue(descriptionOption),
|
result.GetValue(descriptionOption),
|
||||||
result.GetValue(jsonOption),
|
result.GetValue(jsonOption),
|
||||||
result.GetValue(titleOption),
|
result.GetValue(titleOption),
|
||||||
result.GetValue(updateJsonOption),
|
result.GetValue(updateJsonOption),
|
||||||
result.GetValue(outputOption)));
|
result.GetValue(outputOption),
|
||||||
|
result.GetValue(imageAsIsOption)));
|
||||||
return setCommand;
|
return setCommand;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue