-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProgram.cs
executable file
·90 lines (89 loc) · 3.16 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Text;
using Microsoft.Extensions.CommandLineUtils;
namespace Wolf
{
public class Program
{
public static void Main(string[] args)
{
Console.OutputEncoding = Encoding.UTF8;
var config = new Config();
var showLogo = true;
var app = new CommandLineApplication(false)
{
Name = "wolf",
Description = "markdown to static blog post generator"
};
var input = app.Option(
"-i | --inputDirectory <directory>",
"Input directory of blog posts",
CommandOptionType.SingleValue);
var output = app.Option(
"-o | --outputDirectory <directory>",
"Output directory of blog posts",
CommandOptionType.SingleValue);
var noIndex = app.Option(
"-nx | --noIndex",
"Do not generate index (posts.json)",
CommandOptionType.NoValue);
var index = app.Option(
"-x | --indexDirectory <directory>",
"Directory where index (posts.json) file is written",
CommandOptionType.SingleValue);
var prefix = app.Option(
"-p | --imagePrefix <prefix>",
"Prefix added to image paths.",
CommandOptionType.SingleValue);
var tags = app.Option(
"-t | --tagFile",
"Generate 'tags.json' file.",
CommandOptionType.NoValue);
var verbose = app.Option(
"-v | --verbose",
"Show detailed output.",
CommandOptionType.NoValue);
var logo = app.Option(
"-n | --nologo",
"Do not display logo.",
CommandOptionType.NoValue);
app.HelpOption("-? | -h | --help");
app.OnExecute(() =>
{
config.InputDirectory = input.HasValue() ? input.Value() : "posts";
config.OutputDirectory = output.HasValue() ? output.Value() : config.InputDirectory;
config.IndexDirectory = index.HasValue() ? index.Value() : config.OutputDirectory;
config.ImagePrefix = prefix.HasValue() ? prefix.Value() : "/" + config.OutputDirectory + "/";
config.GenerateIndex = !noIndex.HasValue();
config.GenerateTagsFile = tags.HasValue();
config.Verbose = verbose.HasValue();
showLogo = !logo.HasValue();
return 1;
});
if (app.Execute(args) == 1)
{
if (showLogo)
{
Console.WriteLine();
Console.WriteLine(@"/\_/\ wolf");
Console.WriteLine(@"|` ´|");
Console.WriteLine(@" \-/ markdown to static blog post generator");
Console.WriteLine();
}
if (config.Verbose)
{
Console.WriteLine("input directory : " + config.InputDirectory);
Console.WriteLine("output directory : " + config.OutputDirectory);
Console.WriteLine("index directory : " + config.IndexDirectory);
Console.WriteLine("image prefix : " + config.ImagePrefix);
Console.WriteLine("generate 'posts.json': " + config.GenerateIndex);
Console.WriteLine("generate 'tags.json' : " + config.GenerateTagsFile);
}
var converter = new Converter(config);
converter.Run();
Console.WriteLine("DONE");
Console.WriteLine();
}
}
}
}