forked from MidKnightXI/metadate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
55 lines (50 loc) · 1.89 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.CommandLine;
using Metadate;
internal static class Program
{
private static int Main(string[] args)
{
var rootCommand = new RootCommand("MetaDate - Media ordering by dates");
var target = new Argument<DirectoryInfo>(
name: "target",
description: "The directory containing the images to analyze.")
{
Arity = ArgumentArity.ExactlyOne
};
var output = new Option<DirectoryInfo>(
name: "--output",
description: "Where to copy the files",
getDefaultValue: () => new DirectoryInfo("./"))
{
Arity = ArgumentArity.ExactlyOne,
};
var orderByOption = new Option<string>(
name: "--orderBy",
description: "Specify the type of date information to process: 'day', 'month', or 'year'",
getDefaultValue: () => "day")
{
Arity = ArgumentArity.ExactlyOne,
};
orderByOption.AddValidator(result =>
{
var value = result.GetValueOrDefault<string>();
if (value is not "day" && value is not "month" && value is not "year")
{
result.ErrorMessage = "The value for --orderBy must be 'day', 'month', or 'year'.";
}
});
rootCommand.AddArgument(target);
rootCommand.AddOption(output);
rootCommand.AddOption(orderByOption);
rootCommand.SetHandler((DirectoryInfo targ, DirectoryInfo outputPath, string date) =>
{
if (InfosExtractor.Check(targ) is false)
{
return;
}
var results = InfosExtractor.RetrieveInformation(targ);
InfosExtractor.OrderPictures(results, date, outputPath);
}, target, output, orderByOption);
return rootCommand.Invoke(args);
}
}