impl. description and title options in create command

This commit is contained in:
Syping 2025-10-26 19:23:20 +01:00
parent 7f747f7abc
commit ec2a90a449

View file

@ -6,12 +6,12 @@ internal static class Program {
private static void Main(String[] args) { private static void Main(String[] args) {
RootCommand rootCommand = new("ragephoto-cli Application") { RootCommand rootCommand = new("ragephoto-cli Application") {
GetCommand, SetCommand CreateCommand, GetCommand, SetCommand
}; };
rootCommand.Parse(args).Invoke(); rootCommand.Parse(args).Invoke();
} }
private static void Create(FileInfo photoFile, String format, String jpegFile, String? title) { private static void Create(String format, String jpegFile, String outputFile, String? description, String? title) {
try { try {
using Photo photo = new(); using Photo photo = new();
@ -31,7 +31,7 @@ internal static class Program {
photo.Jpeg = jpegStream.ToArray(); photo.Jpeg = jpegStream.ToArray();
} }
Int32 photoUid = Random.Shared.Next(1, Int32.MaxValue); Int32 photoUid = Random.Shared.Next();
if (photo.Format == PhotoFormat.GTA5) { if (photo.Format == PhotoFormat.GTA5) {
DateTimeOffset photoTime = DateTimeOffset.FromUnixTimeSeconds(Random.Shared.Next(1356998400, 1388534399)); DateTimeOffset photoTime = DateTimeOffset.FromUnixTimeSeconds(Random.Shared.Next(1356998400, 1388534399));
photo.SetHeader("PHOTO - 10/26/25 02:28:08", 798615001, 0); photo.SetHeader("PHOTO - 10/26/25 02:28:08", 798615001, 0);
@ -75,11 +75,19 @@ internal static class Program {
"}"; "}";
} }
photo.Description = description ?? String.Empty;
photo.Title = title ?? "Custom Photo"; photo.Title = title ?? "Custom Photo";
String tempFile = Path.GetTempFileName(); if (outputFile == "-" || outputFile == String.Empty) {
photo.SaveFile(tempFile); using MemoryStream photoStream = new(photo.Save());
File.Move(tempFile, photoFile.FullName, true); using Stream output = Console.OpenStandardOutput();
photoStream.CopyTo(output);
}
else {
String tempFile = Path.GetTempFileName();
photo.SaveFile(tempFile);
File.Move(tempFile, outputFile, true);
}
} }
catch (RagePhotoException exception) { catch (RagePhotoException exception) {
Console.Error.WriteLine(exception.Message); Console.Error.WriteLine(exception.Message);
@ -226,30 +234,35 @@ internal static class Program {
private static Command CreateCommand { private static Command CreateCommand {
get { get {
Argument<FileInfo> photoArgument = new("photo") {
Description = "Photo File"
};
Argument<String> formatArgument = new("format") { Argument<String> formatArgument = new("format") {
Description = "Photo Format", Description = "Photo Format"
}; };
formatArgument.CompletionSources.Add(_ => [ formatArgument.CompletionSources.Add(_ => [
new("gta5"), new("gta5"),
new("rdr2")]); new("rdr2")]);
Argument<String> jpegArgument = new("jpeg") { Argument<String> jpegArgument = new("jpeg") {
Description = "JPEG File", Description = "JPEG File",
DefaultValueFactory = _ => "-"
}; };
Argument<String?> titleArgument = new("title") { Argument<String> outputArgument = new("output") {
Description = "Photo Title", Description = "Output File",
DefaultValueFactory = _ => null DefaultValueFactory = _ => "-"
};
Option<String?> descriptionOption = new("--description", "-d") {
Description = "Photo Description"
};
Option<String?> titleOption = new("--title", "-t") {
Description = "Photo Title"
}; };
Command createCommand = new("create", "Create Photo") { Command createCommand = new("create", "Create Photo") {
photoArgument, formatArgument, jpegArgument, titleArgument formatArgument, jpegArgument, outputArgument, descriptionOption, titleOption
}; };
createCommand.SetAction(result => Create( createCommand.SetAction(result => Create(
result.GetRequiredValue(photoArgument),
result.GetRequiredValue(formatArgument), result.GetRequiredValue(formatArgument),
result.GetRequiredValue(jpegArgument), result.GetRequiredValue(jpegArgument),
result.GetValue(titleArgument))); result.GetRequiredValue(outputArgument),
result.GetValue(descriptionOption),
result.GetValue(titleOption)));
return createCommand; return createCommand;
} }
} }