Skip to content

Commit b45789c

Browse files
author
Viktor Chernev
committed
v0.9.2
1 parent f1bc1a3 commit b45789c

21 files changed

+285
-103
lines changed

@DescribeCompilerAPI/Compiler/DescribeCompiler#Properties.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using DescribeCompiler.Compiler;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
@@ -35,5 +36,24 @@ public string LoadedGrammarName
3536
get;
3637
private set;
3738
}
39+
40+
/// <summary>
41+
/// The artifact mode of the parser:
42+
/// Weather to Make, Take, Both or ignore artifacts all-together
43+
/// </summary>
44+
public ArtifactMode ArtifactMode
45+
{
46+
get;
47+
set;
48+
}
49+
50+
/// <summary>
51+
/// The path to the artifact folder to be used
52+
/// </summary>
53+
public string ArtifactsPath
54+
{
55+
get;
56+
set;
57+
}
3858
}
3959
}

@DescribeCompilerAPI/Compiler/DescribeCompiler#VerbosityHigh.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ bool ParseFolder_HighVerbosity(DirectoryInfo dirInfo, DescribeUnfold unfold)
6969
{
7070
unfold.FailedFiles.Add(filename);
7171
if (STOP_ON_ERROR) return false;
72+
else
73+
{
74+
unfold.Files.RemoveAt(0);
75+
}
7276
}
7377
}
7478

@DescribeCompilerAPI/Compiler/DescribeCompiler#VerbosityLow.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ bool ParseFolder_LowVerbosity(DirectoryInfo dirInfo, DescribeUnfold unfold)
6767
{
6868
unfold.FailedFiles.Add(filename);
6969
if (STOP_ON_ERROR) return false;
70+
else
71+
{
72+
unfold.Files.RemoveAt(0);
73+
}
7074
}
7175
}
7276

@DescribeCompilerAPI/Compiler/DescribeCompiler#VerbosityMedium.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ bool ParseFolder_MediumVerbosity(DirectoryInfo dirInfo, DescribeUnfold unfold)
6969
{
7070
unfold.FailedFiles.Add(filename);
7171
if(STOP_ON_ERROR) return false;
72+
else
73+
{
74+
unfold.Files.RemoveAt(0);
75+
}
7276
}
7377
}
7478

@DescribeCompilerAPI/Translators/DescribeTranslator.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using System.Text;
56
using System.Threading.Tasks;
@@ -43,6 +44,12 @@ public abstract bool IsInitialized
4344
get;
4445
protected set;
4546
}
47+
48+
49+
public abstract string TranslateUnfold(DescribeUnfold u);
50+
public abstract bool LoadExternalTemplates(string path);
51+
public abstract bool LoadInternalTemplates(string name);
52+
4653
}
4754
}
4855
// After we have parsed our files and optimized the resulting parse tree to content in an Unfold

@DescribeCompilerAPI/Translators/HtmlTranslator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public HtmlTranslator()
107107
/// </summary>
108108
/// <param name="path">The path to the desired templates folder</param>
109109
/// <returns>True if successful</returns>
110-
public bool LoadExternalTemplates(string path)
110+
public override bool LoadExternalTemplates(string path)
111111
{
112112
try
113113
{
@@ -159,7 +159,7 @@ public bool LoadExternalTemplates(string path)
159159
/// </summary>
160160
/// <param name="name">The name of the internal folder</param>
161161
/// <returns>True if successful</returns>
162-
public bool LoadInternalTemplates(string name)
162+
public override bool LoadInternalTemplates(string name)
163163
{
164164
try
165165
{
@@ -193,7 +193,7 @@ public bool LoadInternalTemplates(string name)
193193
/// </summary>
194194
/// <param name="u">The unfold to be translated</param>
195195
/// <returns>The generated html code</returns>
196-
public string TranslateUnfold(DescribeUnfold u)
196+
public override string TranslateUnfold(DescribeUnfold u)
197197
{
198198
if (IsInitialized == false) return null;
199199

@DescribeCompilerAPI/Translators/JsonTranslator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public JsonTranslator(Action<string> logText, Action<string> logError, Action<st
284284
/// </summary>
285285
/// <param name="path">The path to the desired templates folder</param>
286286
/// <returns>True if successful</returns>
287-
public bool LoadExternalTemplates(string path)
287+
public override bool LoadExternalTemplates(string path)
288288
{
289289
try
290290
{
@@ -337,7 +337,7 @@ public bool LoadExternalTemplates(string path)
337337
/// </summary>
338338
/// <param name="name">The name of the internal folder</param>
339339
/// <returns>True if successful</returns>
340-
public bool LoadInternalTemplates(string name)
340+
public override bool LoadInternalTemplates(string name)
341341
{
342342
try
343343
{
@@ -374,7 +374,7 @@ public bool LoadInternalTemplates(string name)
374374
/// </summary>
375375
/// <param name="u">The unfold to be translated</param>
376376
/// <returns>The generated JSON code</returns>
377-
public string TranslateUnfold(DescribeUnfold u)
377+
public override string TranslateUnfold(DescribeUnfold u)
378378
{
379379
if (IsInitialized == false) return null;
380380

@DescribeCompilerCLI/DescribeCompilerCLI.csproj.user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
4-
<StartArguments>-h</StartArguments>
4+
<StartArguments>parse-folder "C:\Users\Viktor Chernev\Desktop\docs-scratch\TestData" "C:\Users\Viktor Chernev\Desktop\docs-scratch\result.json" template="JSON_COMMONER" verbosity=low logfile="C:\Users\Viktor Chernev\Desktop\docs-scratch\last-log.txt" dsonly toponly=false onerror=ignore</StartArguments>
55
</PropertyGroup>
66
<PropertyGroup>
77
<PublishUrlHistory>C:\Users\Viktor Chernev\Desktop\DescribeParser\%40CompilerCLI\Release\|publish\</PublishUrlHistory>

@DescribeCompilerCLI/FunctionsArguments.cs

Lines changed: 45 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
using DescribeCompiler;
22
using System;
3-
using System.Collections.Generic;
43
using System.IO;
5-
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
84

95
namespace DescribeCompilerCLI
106
{
@@ -90,7 +86,7 @@ internal static bool readInputFileArgument(string arg, int argindex)
9086
}
9187
catch (Exception ex)
9288
{
93-
Messages.printArgumentError(arg, argindex, "is not a valid file or folder");
89+
Messages.printArgumentError(arg, argindex, "is not a valid file");
9490
return false;
9591
}
9692
}
@@ -120,7 +116,7 @@ internal static bool readInputFolderArgument(string arg, int argindex)
120116
}
121117
catch (Exception ex)
122118
{
123-
Messages.printArgumentError(arg, argindex, "is not a valid file or folder");
119+
Messages.printArgumentError(arg, argindex, "is not a valid folder");
124120
return false;
125121
}
126122
}
@@ -131,7 +127,7 @@ internal static bool readInputFolderArgument(string arg, int argindex)
131127
/// <param name="arg">The argument raw text</param>
132128
/// <param name="argindex">The index of the argument (for logging purposes)</param>
133129
/// <returns>True if successful</returns>
134-
internal static bool readOutputArgument(string arg, int argindex)
130+
internal static bool readOutputArgument(string arg, int argindex, bool isDir)
135131
{
136132
try
137133
{
@@ -155,8 +151,7 @@ internal static bool readOutputArgument(string arg, int argindex)
155151
DirectoryInfo di = Directory.GetParent(arg);
156152
if (di.Exists)
157153
{
158-
if (Path.GetFileName(arg) == string.Empty) Datnik.isOutputDir = true;
159-
else Datnik.isOutputDir = false;
154+
Datnik.isOutputDir = isDir;
160155
Datnik.output = arg;
161156
return true;
162157
}
@@ -204,17 +199,9 @@ internal static bool readOutputFileArgument(string arg, int argindex)
204199
DirectoryInfo di = Directory.GetParent(arg);
205200
if (di.Exists)
206201
{
207-
if (Path.GetFileName(arg) == string.Empty)
208-
{
209-
Messages.printArgumentError(arg, argindex, "is a folder. File is required");
210-
return false;
211-
}
212-
else
213-
{
214-
Datnik.output = arg;
215-
Datnik.isOutputDir = false;
216-
return true;
217-
}
202+
Datnik.output = arg;
203+
Datnik.isOutputDir = false;
204+
return true;
218205
}
219206
else
220207
{
@@ -241,13 +228,13 @@ internal static bool readOutputFolderArgument(string arg, int argindex)
241228
{
242229
try
243230
{
244-
//existing file - ok
231+
//existing file - not ok
245232
if (File.Exists(arg))
246233
{
247234
Messages.printArgumentError(arg, argindex, "is a file. Folder is required");
248235
return false;
249236
}
250-
//existing dir - not ok
237+
//existing dir - ok
251238
else if (Directory.Exists(arg))
252239
{
253240
Datnik.output = arg;
@@ -260,17 +247,9 @@ internal static bool readOutputFolderArgument(string arg, int argindex)
260247
DirectoryInfo di = Directory.GetParent(arg);
261248
if (di.Exists)
262249
{
263-
if (Path.GetFileName(arg) == string.Empty)
264-
{
265-
Datnik.output = arg;
266-
Datnik.isOutputDir = true;
267-
return true;
268-
}
269-
else
270-
{
271-
Messages.printArgumentError(arg, argindex, "is a file. Folder is required");
272-
return false;
273-
}
250+
Datnik.output = arg;
251+
Datnik.isOutputDir = true;
252+
return true;
274253
}
275254
else
276255
{
@@ -306,9 +285,8 @@ internal static bool readDsonlyArgument(string arg, int argindex)
306285
Messages.printArgumentError(arg, argindex, "");
307286
return false;
308287
}
309-
else if (val == "true" || val == "l") Datnik.verbosity = LogVerbosity.Low;
310-
else if (val == "medium" || val == "m") Datnik.verbosity = LogVerbosity.Medium;
311-
else if (val == "high" || val == "h") Datnik.verbosity = LogVerbosity.High;
288+
else if (val == "true") Datnik.dsOnly = true;
289+
else if (val == "false") Datnik.dsOnly = false;
312290
else
313291
{
314292
Messages.printArgumentError(arg,
@@ -453,8 +431,7 @@ internal static bool readTemplateArgument(string arg, int argindex)
453431
}
454432
else
455433
{
456-
FileAttributes attr = File.GetAttributes(val);
457-
if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
434+
if(Directory.Exists(val))
458435
{
459436
Datnik.templateName = new DirectoryInfo(val).Name;
460437
Datnik.templatePath = val;
@@ -464,7 +441,6 @@ internal static bool readTemplateArgument(string arg, int argindex)
464441
else
465442
{
466443
string[] names = ResourceUtil.extractResourceNames();
467-
bool flag = false;
468444
foreach (string s in names)
469445
{
470446
if (s.StartsWith("DescribeCompiler.Templates." + val + "."))
@@ -499,27 +475,37 @@ internal static bool readLogfileArgument(string arg, int argindex)
499475
{
500476
try
501477
{
478+
string val = arg.Substring(arg.IndexOf("=") + 1);
479+
if (string.IsNullOrEmpty(val) || string.IsNullOrWhiteSpace(val))
480+
{
481+
Messages.printArgumentError(arg, argindex, "");
482+
return false;
483+
}
484+
//there is a bug in visual studio I think where if your path
485+
//in the command line parameter is in parentheses and ends with
486+
//a backslash, it is treated as an escaped backslash
487+
502488
//existing file - ok
503-
if (File.Exists(arg))
489+
if (File.Exists(val))
504490
{
505-
Datnik.logFilePath = arg;
491+
Datnik.logFilePath = val;
506492
Datnik.logToFile = true;
507493
return true;
508494
}
509495
//existing dir - ok
510-
else if (Directory.Exists(arg))
496+
else if (Directory.Exists(val))
511497
{
512-
Datnik.logFilePath = arg;
498+
Datnik.logFilePath = Path.Combine(val, "lastlog.txt");
513499
Datnik.logToFile = true;
514500
return true;
515501
}
516502
else
517503
{
518504
// notexisting file or dir - we want parent dir to exist
519-
DirectoryInfo di = Directory.GetParent(arg);
505+
DirectoryInfo di = Directory.GetParent(val);
520506
if (di.Exists)
521507
{
522-
Datnik.logFilePath = arg;
508+
Datnik.logFilePath = val;
523509
Datnik.logToFile = true;
524510
return true;
525511
}
@@ -558,9 +544,10 @@ internal static bool readArtifactsArgument(string arg, int argindex)
558544
Messages.printArgumentError(arg, argindex, "");
559545
return false;
560546
}
561-
else if (val == "low" || val == "l") Datnik.verbosity = LogVerbosity.Low;
562-
else if (val == "medium" || val == "m") Datnik.verbosity = LogVerbosity.Medium;
563-
else if (val == "high" || val == "h") Datnik.verbosity = LogVerbosity.High;
547+
else if (val == "m" || val == "makeonly") Datnik.artifactMode = DescribeCompiler.Compiler.ArtifactMode.MakeOnly;
548+
else if (val == "t" || val == "takeonly") Datnik.artifactMode = DescribeCompiler.Compiler.ArtifactMode.TakeOnly;
549+
else if (val == "u" || val == "use") Datnik.artifactMode = DescribeCompiler.Compiler.ArtifactMode.Use;
550+
else if (val == "n" || val == "no") Datnik.artifactMode = DescribeCompiler.Compiler.ArtifactMode.No;
564551
else
565552
{
566553
Messages.printArgumentError(arg,
@@ -588,10 +575,17 @@ internal static bool readArtifactsPathArgument(string arg, int argindex)
588575
{
589576
try
590577
{
578+
string val = arg.Substring(arg.IndexOf("=") + 1);
579+
if (string.IsNullOrEmpty(val) || string.IsNullOrWhiteSpace(val))
580+
{
581+
Messages.printArgumentError(arg, argindex, "");
582+
return false;
583+
}
584+
591585
//existing dir - ok
592-
if (Directory.Exists(arg))
586+
if (Directory.Exists(val))
593587
{
594-
Datnik.artifactsFolderPath = arg;
588+
Datnik.artifactsFolderPath = val;
595589
return true;
596590
}
597591
else
@@ -610,7 +604,4 @@ internal static bool readArtifactsPathArgument(string arg, int argindex)
610604
}
611605
}
612606
}
613-
}
614-
// If we have an error and thus not able to set the datnik
615-
// field, we should reset it. Otherwise we might get half-set datnik
616-
// structure or previous command left-overs in the future
607+
}

0 commit comments

Comments
 (0)