Skip to content

Commit 0332159

Browse files
author
Wes Shaddix
committed
fixed bug while showing history and updated help content output
1 parent 541543d commit 0332159

File tree

3 files changed

+73
-81
lines changed

3 files changed

+73
-81
lines changed

src/SqlCi.Console/ConfigurationValues.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ internal class ConfigurationValues
1515
internal bool ShowHistory { get; set; }
1616
internal bool UseConfigFile { get; set; }
1717
internal bool VersionNumber { get; set; }
18+
internal bool GenerateScript { get; set; }
1819
}
1920
}

src/SqlCi.Console/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ private static OptionSet DefineOptionSet(string[] args, out ConfigurationValues
2929
{"h|help", "show this message and exit", p => config.ShowHelp = p != null},
3030
{"v|version", "show the version number", p => config.VersionNumber = p != null},
3131
{"sh|showHistory", "show the history of scripts ran against the database", p => config.ShowHistory = p != null},
32+
{"g|generateScript", "generates a new script file. Usage: g <environment> <script_name> <script_folder>", p => config.GenerateScript = p != null}
3233
};
3334

3435
try
Lines changed: 71 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-

2-
using SqlCi.ScriptRunner.Constants;
1+
using SqlCi.ScriptRunner.Constants;
32
using SqlCi.ScriptRunner.Exceptions;
43
using System.IO;
54

@@ -8,81 +7,78 @@ namespace SqlCi.ScriptRunner
87
public class ScriptConfiguration
98
{
109
private string _connectionString;
10+
private string _environment;
11+
private string _releaseNumber;
1112
private string _resetConnectionString;
12-
private string _scriptsFolder;
13+
private bool _resetDatabase;
1314
private string _resetFolder;
14-
private string _releaseNumber;
15+
private string _scriptsFolder;
1516
private string _scriptTable;
16-
private bool _resetDatabase;
1717
private bool _verified;
18-
private string _environment;
19-
20-
public string ScriptsFolder
21-
{
22-
get { return _scriptsFolder; }
23-
}
24-
2518
public string ConnectionString
2619
{
2720
get { return _connectionString; }
2821
}
29-
30-
public string ScriptTable
22+
public string Environment
3123
{
32-
get { return _scriptTable; }
24+
get { return _environment; }
25+
}
26+
public bool IsVerified
27+
{
28+
get { return _verified; }
3329
}
34-
3530
public string ReleaseNumber
3631
{
3732
get { return _releaseNumber; }
3833
}
39-
40-
public bool IsVerified
34+
public string ResetConnectionString
4135
{
42-
get { return _verified; }
36+
get { return _resetConnectionString; }
4337
}
44-
4538
public bool ResetDatabase
4639
{
4740
get { return _resetDatabase; }
4841
}
49-
5042
public string ResetFolder
5143
{
5244
get { return _resetFolder; }
5345
}
54-
55-
public string Environment
46+
public string ScriptsFolder
5647
{
57-
get { return _environment; }
48+
get { return _scriptsFolder; }
5849
}
59-
60-
public string ResetConnectionString
50+
public string ScriptTable
6151
{
62-
get { return _resetConnectionString; }
52+
get { return _scriptTable; }
6353
}
6454

65-
public ScriptConfiguration WithConnectionString(string connectionString)
55+
public ScriptConfiguration Verify()
6656
{
67-
_connectionString = connectionString;
68-
return this;
69-
}
57+
// do a sanity check on our variables and make sure we have everything we need to run
58+
// the scripts
59+
ValidateConnectionString();
60+
ValidateScriptsFolder();
61+
ValidateResetFolder();
62+
ValidateReleaseNumber();
63+
ValidateScriptTable();
64+
ValidateEnvironment();
65+
ValidateResetConnectionString();
66+
67+
// if we got this far without errors then we are ready to run scripts
68+
_verified = true;
7069

71-
public ScriptConfiguration WithScriptsFolder(string scriptsFolder)
72-
{
73-
_scriptsFolder = scriptsFolder;
7470
return this;
7571
}
7672

77-
public ScriptConfiguration WithResetDatabase(bool resetDatabase)
73+
public ScriptConfiguration WithConnectionString(string connectionString)
7874
{
79-
_resetDatabase = resetDatabase;
75+
_connectionString = connectionString;
8076
return this;
8177
}
8278

83-
public ScriptConfiguration WithResetFolder(string resetFolder)
79+
public ScriptConfiguration WithEnvironment(string environment)
8480
{
85-
_resetFolder = resetFolder;
81+
_environment = environment;
8682
return this;
8783
}
8884

@@ -92,68 +88,49 @@ public ScriptConfiguration WithReleaseNumber(string releaseNumber)
9288
return this;
9389
}
9490

95-
public ScriptConfiguration WithScriptTable(string scriptVersionTable)
91+
public ScriptConfiguration WithResetConnectionString(string resetConnectionString)
9692
{
97-
_scriptTable = scriptVersionTable;
93+
_resetConnectionString = resetConnectionString;
9894
return this;
9995
}
10096

101-
public ScriptConfiguration WithEnvironment(string environment)
97+
public ScriptConfiguration WithResetDatabase(bool resetDatabase)
10298
{
103-
_environment = environment;
99+
_resetDatabase = resetDatabase;
104100
return this;
105101
}
106102

107-
public ScriptConfiguration WithResetConnectionString(string resetConnectionString)
103+
public ScriptConfiguration WithResetFolder(string resetFolder)
108104
{
109-
_resetConnectionString = resetConnectionString;
105+
_resetFolder = resetFolder;
110106
return this;
111107
}
112108

113-
public ScriptConfiguration Verify()
109+
public ScriptConfiguration WithScriptsFolder(string scriptsFolder)
114110
{
115-
// do a sanity check on our variables and make sure we have
116-
// everything we need to run the scripts
117-
ValidateConnectionString();
118-
ValidateScriptsFolder();
119-
ValidateResetFolder();
120-
ValidateReleaseNumber();
121-
ValidateScriptTable();
122-
ValidateEnvironment();
123-
ValidateResetConnectionString();
124-
125-
// if we got this far without errors then we are ready to run scripts
126-
_verified = true;
127-
111+
_scriptsFolder = scriptsFolder;
128112
return this;
129113
}
130114

131-
private void ValidateEnvironment()
115+
public ScriptConfiguration WithScriptTable(string scriptVersionTable)
132116
{
133-
if (string.IsNullOrEmpty(_environment))
134-
{
135-
throw new MissingEnvironmentException(ExceptionMessages.MissingEnvironment);
136-
}
117+
_scriptTable = scriptVersionTable;
118+
return this;
137119
}
138120

139-
private void ValidateScriptsFolder()
121+
private void ValidateConnectionString()
140122
{
141-
if (string.IsNullOrEmpty(_scriptsFolder))
142-
{
143-
throw new MissingScriptsFolderException(ExceptionMessages.MissingScriptsFolder);
144-
}
145-
146-
if (!Directory.Exists(_scriptsFolder))
123+
if (string.IsNullOrEmpty(_connectionString))
147124
{
148-
throw new ScriptsFolderDoesNotExistException(ExceptionMessages.ScriptsFolderDoesNotExist);
125+
throw new MissingConnectionStringException(ExceptionMessages.MissingConnectionString);
149126
}
150127
}
151128

152-
private void ValidateConnectionString()
129+
private void ValidateEnvironment()
153130
{
154-
if (string.IsNullOrEmpty(_connectionString))
131+
if (string.IsNullOrEmpty(_environment))
155132
{
156-
throw new MissingConnectionStringException(ExceptionMessages.MissingConnectionString);
133+
throw new MissingEnvironmentException(ExceptionMessages.MissingEnvironment);
157134
}
158135
}
159136

@@ -165,11 +142,11 @@ private void ValidateReleaseNumber()
165142
}
166143
}
167144

168-
private void ValidateScriptTable()
145+
private void ValidateResetConnectionString()
169146
{
170-
if (string.IsNullOrEmpty(_scriptTable))
147+
if (_resetDatabase && string.IsNullOrEmpty(_resetConnectionString))
171148
{
172-
throw new MissingScriptTableException(ExceptionMessages.MissingScriptTable);
149+
throw new MissingConnectionStringException(ExceptionMessages.MissingResetConnectionString);
173150
}
174151
}
175152

@@ -186,12 +163,25 @@ private void ValidateResetFolder()
186163
}
187164
}
188165

189-
private void ValidateResetConnectionString()
166+
private void ValidateScriptsFolder()
190167
{
191-
if (_resetDatabase && string.IsNullOrEmpty(_resetConnectionString))
168+
if (string.IsNullOrEmpty(_scriptsFolder))
192169
{
193-
throw new MissingConnectionStringException(ExceptionMessages.MissingResetConnectionString);
170+
throw new MissingScriptsFolderException(ExceptionMessages.MissingScriptsFolder);
171+
}
172+
173+
if (!Directory.Exists(_scriptsFolder))
174+
{
175+
throw new ScriptsFolderDoesNotExistException(ExceptionMessages.ScriptsFolderDoesNotExist);
176+
}
177+
}
178+
179+
private void ValidateScriptTable()
180+
{
181+
if (string.IsNullOrEmpty(_scriptTable))
182+
{
183+
throw new MissingScriptTableException(ExceptionMessages.MissingScriptTable);
194184
}
195185
}
196186
}
197-
}
187+
}

0 commit comments

Comments
 (0)