Skip to content

Commit 56b76ec

Browse files
committed
Added user friendly file not found message for grun console app.
1 parent 992bd12 commit 56b76ec

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

Grun/Program.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,27 @@ private static void Main(string[] args)
138138
return;
139139
}
140140

141-
var guideResult = grammar.LoadSyntaxHighlightingGuide();
142-
guide = guideResult != null ? guideResult.Item2 : new HeuristicSyntaxHighlightingGuide(_Settings);
141+
// To be used later once syntax highlighting for the console is enabled.
142+
//var guideResult = grammar.LoadSyntaxHighlightingGuide();
143+
//guide = guideResult != null ? guideResult.Item2 : new HeuristicSyntaxHighlightingGuide(_Settings);
143144

144-
var data = string.Empty;
145+
string data;
145146

146147
if (!string.IsNullOrEmpty(o.FileName))
147148
{
149+
if (!File.Exists(o.FileName))
150+
{
151+
Console.WriteLine(Resources.FileNotFoundErrorMessage, o.FileName);
152+
return;
153+
}
154+
148155
var encodingToUse = !string.IsNullOrEmpty(o.EncodingName) ? Encoding.GetEncoding(o.EncodingName) : Encoding.Default;
149156
using (var reader = new StreamReader(o.FileName, encodingToUse))
150157
data = reader.ReadToEnd();
151158
}
152159
else
153160
{
154-
var analyzer = new Analyzer();
161+
//var analyzer = new Analyzer();
155162
var builder = new StringBuilder();
156163
Console.WriteLine(Resources.ReadingFromStandardInputPromptMessage);
157164
var currentLine = Console.CursorTop;

Grun/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Grun/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,7 @@
138138
<data name="UnableToDisplayParseTree" xml:space="preserve">
139139
<value>Cannot display parse tree.</value>
140140
</data>
141+
<data name="FileNotFoundErrorMessage" xml:space="preserve">
142+
<value>File "{0}" could not be found.</value>
143+
</data>
141144
</root>

0 commit comments

Comments
 (0)