Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #11 #12

Merged
merged 3 commits into from
Oct 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ You can also use the commands listed below when using this software:
|-s, --stylesheet|allows to specify a URL to a CSS stylesheet to style the generated HTML files.|
|-o, --output |let's specify a destination folder for the generated HTML files. By default, they will be placed in the dist folder.|
|-l, --lang |accepts a language tag to mark the HTML document. By default, the lang attribute will be set to en-CA|
|-c, --config | indicates the path to a JSON config file. |


## Example

Expand Down
41 changes: 35 additions & 6 deletions glazed-donut/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
using System.Text.RegularExpressions;
using CommandLine;
using CommandLine.Text;
using Newtonsoft.Json.Linq;

namespace glazed_donut
{

class Program
{
const string VERSION = "0.1";
Expand All @@ -21,11 +23,14 @@ class Program

class Options
{
[Option('c', "config", HelpText = "Supports --config for config.json.")]
public string OutputConfigDirectory { get; set; }

[Option('v', "version", HelpText = "Displays the version of the software.")]
public bool Version { get; set; }

[Option('h', "help", HelpText = "Displays this helpful message.")]
public bool Help { get; set; }
public bool Help { get; set; }

[Option('i', "input", HelpText = "Specifies the file name or folder name that it should use to convert from.")]
public string Input { get; set; }
Expand Down Expand Up @@ -59,17 +64,18 @@ static void DisplayHelp<T>(ParserResult<T> result)

static void Main(string[] args)
{
var result = parser.ParseArguments<Options>(args);
var result = parser.ParseArguments<Options>(args);

string inputArgument = null;
string outputDirectory = null;
string stylesheetUrl = null;
string language = null;
string outputConfigDirectory = null;

result.WithParsed(o =>
{
{
if (o.Version)
{
{
Console.WriteLine(VERSION_STRING);
Environment.Exit(0);
}
Expand All @@ -78,7 +84,30 @@ static void Main(string[] args)
DisplayHelp(result);
Environment.Exit(0);
}
else if (!string.IsNullOrWhiteSpace(o.Input))
else if (!string.IsNullOrEmpty(o.OutputConfigDirectory)) {
// parse the JSON
string myJsonString = File.ReadAllText(o.OutputConfigDirectory);
JObject jObject = JObject.Parse(myJsonString);
foreach (KeyValuePair<string, JToken> keyValuePair in jObject)
{
switch (keyValuePair.Key) {
case "input":
o.Input = (string)keyValuePair.Value;
break;
case "output":
o.OutputDirectory = (string)keyValuePair.Value;
break;
case "stylesheet":
o.StylesheetURL = (string)keyValuePair.Value;
break;
case "lang":
o.Lang = (string)keyValuePair.Value;
break;
}
}

}
if (!string.IsNullOrWhiteSpace(o.Input))
{
inputArgument = o.Input;
outputDirectory = o.OutputDirectory;
Expand Down Expand Up @@ -143,7 +172,7 @@ static bool IsFileNameValid
(string fileName)
{
//only process file if the file type is text or markdown
return fileName.EndsWith(".txt") || fileName.EndsWith(".md");
return fileName.EndsWith(".txt") || fileName.EndsWith(".md") || fileName.EndsWith(".json");
}

static bool isMarkDown
Expand Down
1 change: 1 addition & 0 deletions glazed-donut/glazed-donut.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions ssg-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"input": "D:/SchoolWork/OSD600/glazed-donut/Text.txt",
"output": "./build",
"lang": "fr"
}