forked from hphan9/shinny-ssg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
79 lines (70 loc) · 3.01 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
using System;
using System.IO;
using McMaster.Extensions.CommandLineUtils;
namespace shinny_ssg
{
class Program
{
static void Main(string[] args)
{
string DESTINATION = @".\dist";
//initialize new CLI application
var app= new CommandLineApplication<Program>();
Console.WriteLine("Hello World!");
//help option
app.HelpOption();
app.VersionOption("-v|--version", "0.1", "Shinny SSG 0.1");
var inputFileOption = app.Option<string>("-i|--input", "Input file/folder to convert to HTML", CommandOptionType.SingleValue)
.IsRequired();
var outputOption = app.Option<string>("-o|--output", "Output folder for converted file", CommandOptionType.SingleValue);
var cssOption = app.Option<string>("---stylesheet| -s", "Style Sheet for the HTML file", CommandOptionType.SingleValue);
//on excute
app.OnExecute(() =>
{
try
{
var inputname = inputFileOption.Value();
var cssString = cssOption.HasValue() ? cssOption.Value() : null;
if (outputOption.HasValue() && Directory.Exists(outputOption.Value()))
{
DESTINATION = outputOption.Value();
}
else
{
//It will delete all file even though the read or write process fail
System.IO.DirectoryInfo di = new DirectoryInfo(DESTINATION);
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
foreach (DirectoryInfo dir in di.GetDirectories())
{
dir.Delete(true);
}
}
if (File.Exists(inputname))
{
//add try catch block here
//if file can write and read ok we can delete old folder and write new file
FileText temp = new FileText(inputname, DESTINATION, cssString);
temp.saveFile();
}
else if (Directory.Exists(inputname))
{
var f = new Subfolder();
f.createFolder(inputname, DESTINATION, cssString);
}
else
{
Console.WriteLine("File Name is not valid");
}
Console.WriteLine($"File is in folder {DESTINATION}");
}catch(Exception ex)
{
Console.WriteLine("There is an error with file\\folder path");
}
});
app.Execute(args);
}
}
}