Skip to content

Commit

Permalink
fix: autocreate output dir in headless or based on new param added (#32)
Browse files Browse the repository at this point in the history
- Add new 'a' parameter that will autocreate ouput folder if it does not
  exists without promting user

- Create ouput folder automatically when in headless mode if it does not exists

- Fix coding error when IsValid was always false in case user respondes with
  anything but "y" on first prompt to confirm creating output folder
  • Loading branch information
limesw authored May 26, 2024
1 parent 3d392b3 commit aa831fc
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/GoMoPho/Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ public class Arguments
public bool ExtractJpg { get; set; }

public string OutputDirectory => string.IsNullOrWhiteSpace(SplitDirectory) ? null : SplitDirectory;

public bool Headless { get; private set; }

public bool AutoCreateOutputDir { get; private set; }

public Arguments(string[] args, Func<(string directory, bool success)> directoryPicker)
{
ProcessArgs(args);
Expand All @@ -34,14 +36,21 @@ public Arguments(string[] args, Func<(string directory, bool success)> directory
}
while (!string.IsNullOrWhiteSpace(SplitDirectory) && !System.IO.Directory.Exists(SplitDirectory))
{
Console.WriteLine(@"Split directory not found. Shall it be created (y/n)? ");
var key = Console.ReadKey();
Console.WriteLine();
IsValid = IsValid && key.Key == ConsoleKey.Y;
if (IsValid)
if (AutoCreateOutputDir || Headless)
{
Console.WriteLine(@"Split directory not found. Creating split directory automatically.");
System.IO.Directory.CreateDirectory(OutputDirectory);
}
else
{
Console.WriteLine(@"Split directory not found. Shall it be created (y/n)? ");
var key = Console.ReadKey();
Console.WriteLine();
if (IsValid && key.Key == ConsoleKey.Y)
{
System.IO.Directory.CreateDirectory(OutputDirectory);
}
}
}
if (System.IO.Directory.Exists(SplitDirectory))
{
Expand Down Expand Up @@ -96,6 +105,11 @@ private void ProcessArgs(string[] args)
Headless = true;
break;

case "a":
case "AutoCreateOutputDir":
AutoCreateOutputDir = true;
break;

default:
Help(@"You have not supplied valid arguments in the command line
Expand Down Expand Up @@ -130,6 +144,10 @@ A separate directory that will create two files per motion photo
h
Headless / no-prompt mode.
a
Create ouput directory automatically if it does not exists
For example if you type the following arguments when running me:
d ""C:\Users\Clive\OneDrive\Documents\Pictures\Camera Roll"" s ""Output\"" g p ""*.jpg""
Expand Down

0 comments on commit aa831fc

Please sign in to comment.