Skip to content

Commit 4d13cbc

Browse files
committed
create generates a filename if none has being given
1 parent 1729be4 commit 4d13cbc

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

Commands.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace RagePhoto.Cli;
55

66
internal static partial class Commands {
77

8-
internal static Int32 CreateFunction(String format, String? imageFile, String? description, String? json, String? title, String outputFile) {
8+
internal static Int32 CreateFunction(String format, String? imageFile, String? description, String? json, String? title, String? outputFile) {
99
try {
1010
using Photo photo = new();
1111

@@ -38,14 +38,25 @@ internal static Int32 CreateFunction(String format, String? imageFile, String? d
3838
photo.Description = description ?? String.Empty;
3939
photo.Title = title ?? "Custom Photo";
4040

41-
if (outputFile == "-" || outputFile == String.Empty) {
41+
if (outputFile == "-") {
4242
using Stream output = Console.OpenStandardOutput();
4343
output.Write(photo.Save());
4444
}
4545
else {
4646
String tempFile = Path.GetTempFileName();
4747
photo.SaveFile(tempFile);
48-
File.Move(tempFile, outputFile, true);
48+
if (!String.IsNullOrEmpty(outputFile)) {
49+
File.Move(tempFile, outputFile, true);
50+
}
51+
else {
52+
outputFile = Path.Join(Environment.CurrentDirectory, $"{photo.Format switch {
53+
PhotoFormat.GTA5 => "PGTA5",
54+
PhotoFormat.RDR2 => "PRDR3",
55+
_ => String.Empty
56+
}}{uid}");
57+
File.Move(tempFile, outputFile, true);
58+
Console.WriteLine(outputFile);
59+
}
4960
}
5061
return 0;
5162
}
@@ -241,9 +252,8 @@ internal static Command CreateCommand {
241252
Option<String?> titleOption = new("--title", "-t") {
242253
Description = "Title"
243254
};
244-
Option<String> outputOption = new("--output", "-o") {
245-
Description = "Output File",
246-
DefaultValueFactory = _ => "-"
255+
Option<String?> outputOption = new("--output", "-o") {
256+
Description = "Output File"
247257
};
248258
Command createCommand = new("create", "Create a new Photo") {
249259
formatArgument, imageOption, descriptionOption, jsonOption, titleOption, outputOption
@@ -254,7 +264,7 @@ internal static Command CreateCommand {
254264
result.GetValue(descriptionOption),
255265
result.GetValue(jsonOption),
256266
result.GetValue(titleOption),
257-
result.GetRequiredValue(outputOption)));
267+
result.GetValue(outputOption)));
258268
return createCommand;
259269
}
260270
}

0 commit comments

Comments
 (0)