Skip to content

Commit f1bc1a3

Browse files
author
Viktor Chernev
committed
featureSaveLogsToFile
1 parent 59bcddf commit f1bc1a3

File tree

9 files changed

+116
-33
lines changed

9 files changed

+116
-33
lines changed

@DescribeCompilerAPI/Compiler/DescribeCompiler#Settings.cs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,38 @@ namespace DescribeCompiler
99
public partial class DescribeCompiler
1010
{
1111
/// <summary>
12-
/// Wether to parse only .ds files, or all the files in a directory.
12+
/// Weather to parse only .ds files, or all the files in a directory.
1313
/// </summary>
14-
public const bool PARSE_DS_ONLY = true;
14+
public static bool PARSE_DS_ONLY = true;
1515

1616
/// <summary>
17-
/// Wether to parse files in all subdirectories or only in the top directory.
17+
/// Weather to parse files in all subdirectories or only in the top directory.
1818
/// </summary>
19-
public const bool PARSE_TOP_DIRECTORY_ONLY = false;
19+
public static bool PARSE_TOP_DIRECTORY_ONLY = false;
2020

2121
/// <summary>
22-
/// A string representing the full name of the compiler (with the version)
23-
/// </summary>
24-
public const string COMPILER_NAME = "Describe Compiler v0.9.2";
25-
26-
/// <summary>
27-
/// A string representing the compiler version
22+
/// Weather to stop if there is an error in source code, or skip the file
23+
/// and continue parsing.
2824
/// </summary>
29-
public const string COMPILER_VER = "0.9.2";
25+
public static bool STOP_ON_ERROR = true;
3026

3127
/// <summary>
3228
/// The default grammar file to be loaded with this version of the compiler.
3329
/// The grammar is usually left alone, unless there is a very good reason to be changed,
3430
/// which, on the other hand, makes this the de facto grammar that is used.
3531
/// </summary>
36-
public const GrammarName DEFAULT_GRAMMAR = GrammarName.Decorators;
32+
public static GrammarName DEFAULT_GRAMMAR = GrammarName.Decorators;
33+
34+
35+
36+
/// <summary>
37+
/// A string representing the full name of the compiler (with the version)
38+
/// </summary>
39+
public static string COMPILER_NAME = "Describe Compiler v0.9.2";
40+
41+
/// <summary>
42+
/// A string representing the compiler version
43+
/// </summary>
44+
public static string COMPILER_VER = "0.9.2";
3745
}
3846
}

@DescribeCompilerAPI/Compiler/DescribeCompiler#VerbosityHigh.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ bool ParseFolder_HighVerbosity(DirectoryInfo dirInfo, DescribeUnfold unfold)
6868
else
6969
{
7070
unfold.FailedFiles.Add(filename);
71-
return false;
71+
if (STOP_ON_ERROR) return false;
7272
}
7373
}
7474

@DescribeCompilerAPI/Compiler/DescribeCompiler#VerbosityLow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ bool ParseFolder_LowVerbosity(DirectoryInfo dirInfo, DescribeUnfold unfold)
6666
else
6767
{
6868
unfold.FailedFiles.Add(filename);
69-
return false;
69+
if (STOP_ON_ERROR) return false;
7070
}
7171
}
7272

@DescribeCompilerAPI/Compiler/DescribeCompiler#VerbosityMedium.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ bool ParseFolder_MediumVerbosity(DirectoryInfo dirInfo, DescribeUnfold unfold)
6868
else
6969
{
7070
unfold.FailedFiles.Add(filename);
71-
return false;
71+
if(STOP_ON_ERROR) return false;
7272
}
7373
}
7474

@DescribeCompilerCLI/FunctionsMain.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ internal static bool Compile()
144144
Messages.ConsoleLogInfo,
145145
Messages.ConsoleLogParseInfo);
146146

147+
DescribeCompiler.DescribeCompiler.PARSE_TOP_DIRECTORY_ONLY = Datnik.topOnly;
148+
DescribeCompiler.DescribeCompiler.PARSE_DS_ONLY = Datnik.dsOnly;
149+
DescribeCompiler.DescribeCompiler.STOP_ON_ERROR = Datnik.requireSuccess;
150+
//template
151+
//artifacts
152+
//ARTIFACTS_PATH
153+
147154
//find out which translator to use
148155
JsonTranslator translator = new JsonTranslator(
149156
Messages.ConsoleLog,

@DescribeCompilerCLI/FunctionsMessages.cs

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Reflection;
55
using System.Text;
66
using System.Threading.Tasks;
7+
using static System.Net.Mime.MediaTypeNames;
78

89
namespace DescribeCompilerCLI
910
{
@@ -79,6 +80,14 @@ internal static void printLogo3()
7980
}
8081
internal static void printLogo3(ConsoleColor logoColor)
8182
{
83+
Log += @" /\\\\ /\\\\ /\\\\ /\\\\ /\\\\ /\\\\ /\\\\ /\\\\ " + Environment.NewLine;
84+
Log += @" / \\\\ / \\\\ / \\\\ / \\\\ / \\\\ _\ \\\\ / \\\\ / \\\\ " + Environment.NewLine;
85+
Log += @" / /\ \\\\ / \ \\\\ /\ \ \\\\ / /\ \\\\ / \ \\\\ /\/ \\\\ / \ \\\\ / \ \\\\" + Environment.NewLine;
86+
Log += @" \ \/ //// \ \ \//// \ \ \//// \ \\\//// \| //// \ /\//// \ \ //// \ \ \////" + Environment.NewLine;
87+
Log += @" \ //// \ \//// \ //// \ \\\\ | \//// \ \\\\ \ //// \ \//// " + Environment.NewLine;
88+
Log += @" \//// \//// \//// \//// \|||| \//// \//// \//// " + Environment.NewLine;
89+
Log += Environment.NewLine;
90+
8291
ConsoleColor col = Console.ForegroundColor;
8392
Console.ForegroundColor = logoColor;
8493
Console.WriteLine();
@@ -97,6 +106,14 @@ internal static void printLogo2()
97106
}
98107
internal static void printLogo2(ConsoleColor logoColor)
99108
{
109+
Log += @" /\\\ /\\\ /\\\ /\\\ /\\\ /\\\ /\\\ /\\\ " + Environment.NewLine;
110+
Log += @" / \\\ / \\\ / \\\ / \\\ / \\\ _\ \\\ / \\\ / \\\ " + Environment.NewLine;
111+
Log += @" / /\ \\\ / \ \\\ /\ \ \\\ / /\ \\\ / \ \\\ /\/ \\\ / \ \\\ / \ \\\" + Environment.NewLine;
112+
Log += @" \ \/ /// \ \ \/// \ \ \/// \ \\\/// \| /// \ /\/// \ \ /// \ \ \///" + Environment.NewLine;
113+
Log += @" \ /// \ \/// \ /// \ \\\ | \/// \ \\\ \ /// \ \/// " + Environment.NewLine;
114+
Log += @" \/// \/// \/// \/// \||| \/// \/// \/// " + Environment.NewLine;
115+
Log += Environment.NewLine;
116+
100117
ConsoleColor col = Console.ForegroundColor;
101118
Console.ForegroundColor = logoColor;
102119
Console.WriteLine();
@@ -115,6 +132,14 @@ internal static void printLogo3Bicolor()
115132
}
116133
internal static void printLogo3Bicolor(ConsoleColor colorA, ConsoleColor colorB)
117134
{
135+
Log += @" /\\\\ /\\\\ /\\\\ /\\\\ /\\\\ /\\\\ /\\\\ /\\\\ " + Environment.NewLine;
136+
Log += @" / \\\\ / \\\\ / \\\\ / \\\\ / \\\\ _\ \\\\ / \\\\ / \\\\ " + Environment.NewLine;
137+
Log += @" / /\ \\\\ / \ \\\\ /\ \ \\\\ / /\ \\\\ / \ \\\\ /\/ \\\\ / \ \\\\ / \ \\\\" + Environment.NewLine;
138+
Log += @" \ \/ //// \ \ \//// \ \ \//// \ \\\//// \| //// \ /\//// \ \ //// \ \ \////" + Environment.NewLine;
139+
Log += @" \ //// \ \//// \ //// \ \\\\ | \//// \ \\\\ \ //// \ \//// " + Environment.NewLine;
140+
Log += @" \//// \//// \//// \//// \|||| \//// \//// \//// " + Environment.NewLine;
141+
Log += Environment.NewLine;
142+
118143
ConsoleColor col = Console.ForegroundColor;
119144
Console.WriteLine();
120145

@@ -256,59 +281,62 @@ internal static void printCmdLine(string[] args)
256281
}
257282
internal static void printExtTemplatesSuccess(string path)
258283
{
284+
//add to log
285+
Log += "Templates outputted to \"" + path + "\"" + Environment.NewLine;
286+
Log += "Press any key to exit." + Environment.NewLine;
287+
288+
//add to console
259289
Console.ForegroundColor = INFO_COLOR;
260290
Console.WriteLine("Templates outputted to \"" + path + "\"");
261291
Console.WriteLine("Press any key to exit.");
262-
263292
Console.ForegroundColor = TEXT_COLOR;
264293
Console.ReadKey();
265294
}
266295
internal static void printHelpMessage()
267296
{
268297
ConsoleLogInfo("-----------------------------------------------------------------");
269-
Console.WriteLine("usage: " + thisName + " help | -h");
298+
ConsoleLog("usage: " + thisName + " help | -h");
270299
ConsoleLogInfo("Display this help message");
271-
Console.WriteLine();
300+
ConsoleLog("");
272301
ConsoleLogInfo("-----------------------------------------------------------------");
273-
Console.WriteLine("usage: " + thisName + " ext [ RESULT_PATH ]");
302+
ConsoleLog("usage: " + thisName + " ext [ RESULT_PATH ]");
274303
ConsoleLogInfo("externalize all the templates");
275304
ConsoleLogInfo("* RESULT_PATH (optionally) - specify path to write the template folders to. Current folder will be used otherwise");
276-
Console.WriteLine();
305+
ConsoleLog("");
277306
ConsoleLogInfo("-----------------------------------------------------------------");
278-
Console.WriteLine("usage: " + thisName + " extone TEMPLATE_NAME [ RESULT_PATH ]");
307+
ConsoleLog("usage: " + thisName + " extone TEMPLATE_NAME [ RESULT_PATH ]");
279308
ConsoleLogInfo("externalize a specific template set");
280309
ConsoleLogInfo("TEMPLATE_NAME - the template set to be externalized: \"HTML_PARACORD\" or \"JSON_COMMONER\"");
281310
ConsoleLogInfo("* RESULT_PATH (optionally) - specify path to write the template folders to. Current folder will be used otherwise");
282-
Console.WriteLine();
311+
ConsoleLog("");
283312
ConsoleLogInfo("-----------------------------------------------------------------");
284-
Console.WriteLine("usage: " + thisName + " parse-file PARSE_PATH RESULT_PATH [ template=(TEMPLATE_NAME|TEMPLATE_PATH) ]\n[ dsonly[=true|=false] ] [ verbosity=<verb> | log-verbosity=<verb> ] [ onerror=<verb> ] \n[ artifacts=<verb> [artifacts-path=ARTIFACTS_PATH ]] [ logfile=LOG_PATH ]");
313+
ConsoleLog("usage: " + thisName + " parse-file PARSE_PATH RESULT_PATH [ template=(TEMPLATE_NAME|TEMPLATE_PATH) ]\n[ dsonly[=true|=false] ] [ verbosity=<verb> | log-verbosity=<verb> ]\n[ artifacts=<verb> [artifacts-path=ARTIFACTS_PATH ]] [ logfile=LOG_PATH ]");
285314
ConsoleLogInfo("template - the name (inbuilt) or path (external) of the template set to use");
286315
ConsoleLogInfo("PARSE_PATH - the path of the file to parse");
287316
ConsoleLogInfo("RESULT_PATH - the path of the file to write the result to (existing file or not)");
288317
ConsoleLogInfo("* dsonly - weather to omit files that are not Describe source files (\".DS\"). (default is true): \"true\", \"false\"");
289318
ConsoleLogInfo("* verbosity - set the log verbosity of the parser (default is high): \"l\", \"low\", \"m\", \"medium\", \"h\", \"high\"");
290319
ConsoleLogInfo("* log-verbosity - can be used instead of verbosity");
291-
ConsoleLogInfo("* onerror - what to do when there is an error in source code. (default is stop): \"stop\", \"ignore\", \"dart-stop\", \"dart-ignore\"");
292320
ConsoleLogInfo("* artifacts - weather to use artifacts (default is no): \"m\", \"makeonly\", \"t\", \"takeonly\", \"u\", \"use\", \"n\", \"no\"");
293321
ConsoleLogInfo("** ARTIFACTS_PATH - specify path of directory to store artifacts in");
294322
ConsoleLogInfo("* LOG_PATH - specify path of directory or file to output logs to");
295-
Console.WriteLine();
323+
ConsoleLog("");
296324
ConsoleLogInfo("-----------------------------------------------------------------");
297-
Console.WriteLine("usage: " + thisName + " parse-folder PARSE_PATH RESULT_PATH [ template=(TEMPLATE_NAME|TEMPLATE_PATH) ]\n[ dsonly[=<verb>] ] [ toponly[=true|=false] ] [ verbosity=<verb> | log-verbosity=<verb> ]\n[ onerror=<verb> ] [ artifacts=<verb> [artifacts-path=ARTIFACTS_PATH ]] [ logfile=LOG_PATH ]");
325+
ConsoleLog("usage: " + thisName + " parse-folder PARSE_PATH RESULT_PATH [ template=(TEMPLATE_NAME|TEMPLATE_PATH) ]\n[ dsonly[=<verb>] ] [ toponly[=true|=false] ] [ verbosity=<verb> | log-verbosity=<verb> ]\n[ onerror=<verb> ] [ artifacts=<verb> [artifacts-path=ARTIFACTS_PATH ]] [ logfile=LOG_PATH ]");
298326
ConsoleLogInfo("template - the name (inbuilt) or path (external) of the template set to use");
299327
ConsoleLogInfo("PARSE_PATH - the path of the file to parse");
300328
ConsoleLogInfo("RESULT_PATH - the path of the folder to write the result to (existing or not)");
301329
ConsoleLogInfo("* dsonly - weather to omit files that are not Describe source files (\".DS\"). (default is true): \"true\", \"false\"");
302330
ConsoleLogInfo("* toponly - weather to parse files in child directories or not. (default is false): \"true\", \"false\"");
303331
ConsoleLogInfo("* verbosity - set the log verbosity of the parser (default is high): \"l\", \"low\", \"m\", \"medium\", \"h\", \"high\"");
304332
ConsoleLogInfo("* log-verbosity - can be used instead of verbosity");
305-
ConsoleLogInfo("* onerror - what to do when there is an error in source code. (default is stop): \"stop\", \"ignore\", \"dart-stop\", \"dart-ignore\"");
333+
ConsoleLogInfo("* onerror - what to do when there is an error in source code. (default is stop): \"stop\", \"ignore\"");
306334
ConsoleLogInfo("* artifacts - weather to use artifacts (default is no): \"m\", \"makeonly\", \"t\", \"takeonly\", \"u\", \"use\", \"n\", \"no\"");
307335
ConsoleLogInfo("** ARTIFACTS_PATH - specify path of directory to store artifacts in");
308336
ConsoleLogInfo("* LOG_PATH - specify path of directory or file to output logs to");
309-
Console.WriteLine();
337+
ConsoleLog("");
310338
ConsoleLogInfo("-----------------------------------------------------------------");
311-
Console.WriteLine("about: " + DescribeCompiler.DescribeCompiler.COMPILER_NAME);
339+
ConsoleLog("about: " + DescribeCompiler.DescribeCompiler.COMPILER_NAME);
312340
ConsoleLogInfo("Describe is a domain specific language used to write and maintain complex data lists");
313341
ConsoleLogInfo("that are compiled on demand to html, xaml, xml, sql, json and any other language needed.");
314342
ConsoleLogInfo("Describe is licensed under the GNU Affero General Public License v3.0");
@@ -317,13 +345,16 @@ internal static void printHelpMessage()
317345

318346

319347
Console.ForegroundColor = INFO_COLOR;
348+
Log += "Press any key to exit." + Environment.NewLine;
320349
Console.WriteLine("Press any key to exit.");
321350
Console.ForegroundColor = TEXT_COLOR;
322351
Console.ReadKey();
323352
}
324353
internal static void printWarning(string message)
325354
{
326355
Console.ForegroundColor = INFO_COLOR;
356+
Log += "Warning: " + message + Environment.NewLine;
357+
Log += "Press any key to continue." + Environment.NewLine;
327358
Console.WriteLine("Warning: " + message);
328359
Console.WriteLine("Press any key to continue.");
329360

@@ -333,12 +364,14 @@ internal static void printWarning(string message)
333364
internal static void printNoArgumentsError()
334365
{
335366
Console.ForegroundColor = ERROR_COLOR;
367+
Log += "No arguments or invalid argument count." + Environment.NewLine;
336368
Console.WriteLine("No arguments or invalid argument count.");
337369

338370
Console.ForegroundColor = TEXT_COLOR;
339371
printHelpMessage();
340372

341373
Console.ForegroundColor = INFO_COLOR;
374+
Log += "Press any key to exit." + Environment.NewLine;
342375
Console.WriteLine("Press any key to exit.");
343376

344377
Console.ForegroundColor = TEXT_COLOR;
@@ -348,12 +381,14 @@ internal static void printArgumentError(string arg, int argIndex)
348381
{
349382
Console.ForegroundColor = ERROR_COLOR;
350383
if (ONE_BASED_ARG_INDEX) argIndex++;
384+
Log += "Invalid argument " + argIndex.ToString() + " - \"" + arg + "\"" + Environment.NewLine;
351385
Console.WriteLine("Invalid argument " + argIndex.ToString() + " - \"" + arg + "\"");
352386

353387
Console.ForegroundColor = TEXT_COLOR;
354388
printHelpMessage();
355389

356390
Console.ForegroundColor = INFO_COLOR;
391+
Log += "Press any key to exit." + Environment.NewLine;
357392
Console.WriteLine("Press any key to exit.");
358393

359394
Console.ForegroundColor = TEXT_COLOR;
@@ -363,9 +398,12 @@ internal static void printArgumentError(string arg, int argIndex, string message
363398
{
364399
Console.ForegroundColor = ERROR_COLOR;
365400
if (ONE_BASED_ARG_INDEX) argIndex++;
401+
Log += "Invalid argument " + argIndex.ToString() +
402+
" - \"" + arg + "\" - " + message + Environment.NewLine;
366403
Console.WriteLine("Invalid argument " + argIndex.ToString() + " - \"" + arg + "\" - " + message);
367404

368405
Console.ForegroundColor = INFO_COLOR;
406+
Log += "Press any key to exit." + Environment.NewLine;
369407
Console.WriteLine("Press any key to exit.");
370408

371409
Console.ForegroundColor = TEXT_COLOR;
@@ -374,9 +412,11 @@ internal static void printArgumentError(string arg, int argIndex, string message
374412
internal static void printFatalError(string message)
375413
{
376414
Console.ForegroundColor = ERROR_COLOR;
415+
Log += "Fatal error: " + message + Environment.NewLine;
377416
Console.WriteLine("Fatal error: " + message);
378417

379418
Console.ForegroundColor = INFO_COLOR;
419+
Log += "Press any key to exit." + Environment.NewLine;
380420
Console.WriteLine("Press any key to exit.");
381421

382422
Console.ForegroundColor = TEXT_COLOR;
@@ -385,24 +425,33 @@ internal static void printFatalError(string message)
385425

386426

387427
//log
428+
internal static string Log
429+
{
430+
get;
431+
private set;
432+
}
388433
internal static void ConsoleLog(string text)
389434
{
435+
Log += text + Environment.NewLine;
390436
Console.WriteLine(text);
391437
}
392438
internal static void ConsoleLogInfo(string text)
393439
{
440+
Log += text + Environment.NewLine;
394441
Console.ForegroundColor = INFO_COLOR;
395442
Console.WriteLine(text);
396443
Console.ForegroundColor = TEXT_COLOR;
397444
}
398445
internal static void ConsoleLogError(string text)
399446
{
447+
Log += text + Environment.NewLine;
400448
Console.ForegroundColor = ERROR_COLOR;
401449
Console.WriteLine(text);
402450
Console.ForegroundColor = TEXT_COLOR;
403451
}
404452
internal static void ConsoleLogParseInfo(string text)
405453
{
454+
Log += text + Environment.NewLine;
406455
Console.ForegroundColor = MOREINFO_COLOR;
407456
Console.WriteLine(text);
408457
Console.ForegroundColor = TEXT_COLOR;

@DescribeCompilerCLI/Program.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ static void Main(string[] args)
6262
{
6363
Messages.printArgumentError(args[0], 1);
6464
}
65+
66+
//save log to file
67+
if (Datnik.logToFile)
68+
{
69+
File.WriteAllText(Datnik.logFilePath, Messages.Log);
70+
}
6571
}
6672
static void ext(string[] args)
6773
{
@@ -140,10 +146,6 @@ static void parseFile(string[] args)
140146
{
141147
if (Arguments.readVerbosityArgument(cur, i) == false) return;
142148
}
143-
else if (cur.StartsWith("onerror=") && cur.Length > "onerror=".Length)
144-
{
145-
if (Arguments.readOnerrorArgument(cur, i) == false) return;
146-
}
147149
else if (cur.StartsWith("artifacts=") && cur.Length > "artifacts=".Length)
148150
{
149151
if (Arguments.readArtifactsArgument(cur, i) == false) return;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FEATURE: Stop on error
2+
3+
The cli app reads an argument that says wether the compiler should stop
4+
if there is an error in source code, or skip the file and continue with
5+
the compilation process.
6+
7+
In the API, this functionality has been added too
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FEATURE(CLI app): Option to save log to a file
2+
3+
Added a Log property in Messages that acumulates all the logging and can be saved to a file.
4+
If we use the flag logfile=LOG_PATH we do that in Program
5+
6+
internal static string Log
7+
{
8+
get;
9+
private set;
10+
}

0 commit comments

Comments
 (0)