mirror of
https://github.com/Syping/ragephoto-cli.git
synced 2025-12-04 16:51:48 +01:00
create generates a filename if none has being given
This commit is contained in:
parent
1729be49e3
commit
4d13cbc7b0
1 changed files with 17 additions and 7 deletions
24
Commands.cs
24
Commands.cs
|
|
@ -5,7 +5,7 @@ namespace RagePhoto.Cli;
|
||||||
|
|
||||||
internal static partial class Commands {
|
internal static partial class Commands {
|
||||||
|
|
||||||
internal static Int32 CreateFunction(String format, String? imageFile, String? description, String? json, String? title, String outputFile) {
|
internal static Int32 CreateFunction(String format, String? imageFile, String? description, String? json, String? title, String? outputFile) {
|
||||||
try {
|
try {
|
||||||
using Photo photo = new();
|
using Photo photo = new();
|
||||||
|
|
||||||
|
|
@ -38,14 +38,25 @@ internal static partial class Commands {
|
||||||
photo.Description = description ?? String.Empty;
|
photo.Description = description ?? String.Empty;
|
||||||
photo.Title = title ?? "Custom Photo";
|
photo.Title = title ?? "Custom Photo";
|
||||||
|
|
||||||
if (outputFile == "-" || outputFile == String.Empty) {
|
if (outputFile == "-") {
|
||||||
using Stream output = Console.OpenStandardOutput();
|
using Stream output = Console.OpenStandardOutput();
|
||||||
output.Write(photo.Save());
|
output.Write(photo.Save());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String tempFile = Path.GetTempFileName();
|
String tempFile = Path.GetTempFileName();
|
||||||
photo.SaveFile(tempFile);
|
photo.SaveFile(tempFile);
|
||||||
File.Move(tempFile, outputFile, true);
|
if (!String.IsNullOrEmpty(outputFile)) {
|
||||||
|
File.Move(tempFile, outputFile, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
outputFile = Path.Join(Environment.CurrentDirectory, $"{photo.Format switch {
|
||||||
|
PhotoFormat.GTA5 => "PGTA5",
|
||||||
|
PhotoFormat.RDR2 => "PRDR3",
|
||||||
|
_ => String.Empty
|
||||||
|
}}{uid}");
|
||||||
|
File.Move(tempFile, outputFile, true);
|
||||||
|
Console.WriteLine(outputFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -241,9 +252,8 @@ internal static partial class Commands {
|
||||||
Option<String?> titleOption = new("--title", "-t") {
|
Option<String?> titleOption = new("--title", "-t") {
|
||||||
Description = "Title"
|
Description = "Title"
|
||||||
};
|
};
|
||||||
Option<String> outputOption = new("--output", "-o") {
|
Option<String?> outputOption = new("--output", "-o") {
|
||||||
Description = "Output File",
|
Description = "Output File"
|
||||||
DefaultValueFactory = _ => "-"
|
|
||||||
};
|
};
|
||||||
Command createCommand = new("create", "Create a new Photo") {
|
Command createCommand = new("create", "Create a new Photo") {
|
||||||
formatArgument, imageOption, descriptionOption, jsonOption, titleOption, outputOption
|
formatArgument, imageOption, descriptionOption, jsonOption, titleOption, outputOption
|
||||||
|
|
@ -254,7 +264,7 @@ internal static partial class Commands {
|
||||||
result.GetValue(descriptionOption),
|
result.GetValue(descriptionOption),
|
||||||
result.GetValue(jsonOption),
|
result.GetValue(jsonOption),
|
||||||
result.GetValue(titleOption),
|
result.GetValue(titleOption),
|
||||||
result.GetRequiredValue(outputOption)));
|
result.GetValue(outputOption)));
|
||||||
return createCommand;
|
return createCommand;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue