-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandLineUtils.cs
More file actions
56 lines (48 loc) · 1.14 KB
/
CommandLineUtils.cs
File metadata and controls
56 lines (48 loc) · 1.14 KB
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
using System;
using System.IO;
namespace BlogML2Ghost.Core
{
/// <summary>
/// Description of CommandLineUtils.
/// </summary>
public static class CommandLineUtils
{
public static bool TryGetFileLocation(string fileDescription, out string filelocation)
{
Console.Write("{0} (full path)? ", fileDescription);
filelocation = Console.ReadLine();
if (string.IsNullOrWhiteSpace(filelocation))
{
Console.WriteLine("{0} is not a valid file location", filelocation);
return false;
}
if (!File.Exists(filelocation))
{
Console.WriteLine("{0} does not exist", filelocation);
return false;
}
return true;
}
public static bool GetBoolean(string prompt)
{
Console.Write("{0} (type y for yes, no by default) ", prompt);
return Console.ReadLine().ToLower() == "y";
}
public static int GetInteger(string prompt)
{
int returnValue;
bool valid = false;
do
{
Console.Write("{0} ", prompt);
valid = int.TryParse(Console.ReadLine(), out returnValue);
if (!valid)
{
Console.WriteLine("Not a valid integer");
}
} while (!valid);
return returnValue;
}
}
}