-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommandLineParametersHelper.cs
More file actions
105 lines (100 loc) · 4.45 KB
/
CommandLineParametersHelper.cs
File metadata and controls
105 lines (100 loc) · 4.45 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Convert MS Access to Sqlite
// Copyright (C) 2015 Andi Palo
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
using System;
namespace mdb2sq3
{
/// <summary>
/// This class is a simple organizer for the methods related to set specific options the user can set using the command line parameters.
/// </summary>
class CommandLineParametersHelper
{
#region Static Members
public static string databaseSource = null;
public static string databaseTarget = null;
public static string databaseHost = null;
public static bool verbose = false;
public static bool erase = false;
#endregion
#region Public static Methods
/// <summary>
/// Static method to parse and set the options the program can have.
/// </summary>
/// <param name="args">Array of string parameters passed from the command line</param>
/// <returns>True if the arguments are parsed correctly. False if the program should not continue with the given parameters</returns>
public static bool ParseArguments(string[] args)
{
try
{
foreach (string argum in args)
{
if (argum.ToUpper().StartsWith("-S:"))
{
databaseSource = argum.Substring(3);
continue;
}
if (argum.ToUpper().StartsWith("-T:"))
{
databaseTarget = argum.Substring(3);
continue;
}
if (argum.ToUpper().StartsWith("-E"))
{
erase = true;
continue;
}
if (argum.ToUpper().StartsWith("-V"))
{
verbose = true;
continue;
}
if (argum.ToUpper().StartsWith("-?"))
{
System.Console.WriteLine("mdb2sq3: Converts a simple MSAccess Database file into a SQLite database.");
System.Console.WriteLine("usage:");
System.Console.WriteLine("mdb2sq3 -s:sourcefile [-t:targetfile] [options]");
System.Console.WriteLine(" -s:sourcefile Sets the source MSAccess database");
System.Console.WriteLine(" -t:targetfile Sets the target SQLite database");
System.Console.WriteLine(" -e Forces deletion of target file if it exists");
System.Console.WriteLine(" -v Verbose mode.");
System.Console.WriteLine(" -? Prints this help and exits the program.");
return false;
}
System.Console.WriteLine(String.Format("ERROR: Unknown parameter {0}", argum));
return false;
}
}
catch (Exception)
{
System.Console.WriteLine("ERROR: Invalid parameter value.");
return false;
}
// As a final step, check "must set" parameters.
if (databaseSource == null )
{
System.Console.WriteLine(String.Format("ERROR: You need to set MsAccess Database source file"));
return false;
}
if (!System.IO.File.Exists(databaseSource))
{
System.Console.WriteLine(String.Format("ERROR: source file cannot be found"));
return false;
}
return true;
}
#endregion
}
}