Skip to content

Commit

Permalink
Merge pull request #75 from benjamin-hodgson/master
Browse files Browse the repository at this point in the history
Allow specifying a connection string in the console
  • Loading branch information
sethreno committed Mar 9, 2016
2 parents a294ecb + 83113cf commit 548faf1
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions console/DbCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ protected DbCommand(string command, string oneLineDescription) {
IsCommand(command, oneLineDescription);
Options = new OptionSet();
SkipsCommandSummaryBeforeRunning();
HasRequiredOption("s|server=", "server", o => Server = o);
HasRequiredOption("b|database=", "database", o => DbName = o);
HasOption("s|server=", "server", o => Server = o);
HasOption("b|database=", "database", o => DbName = o);
HasOption("c|connectionString=", "connection string", o => ConnectionString = o);
HasOption("u|user=", "user", o => User = o);
HasOption("p|pass=", "pass", o => Pass = o);
HasRequiredOption(
Expand All @@ -31,13 +32,30 @@ protected DbCommand(string command, string oneLineDescription) {

protected string Server { get; set; }
protected string DbName { get; set; }
protected string ConnectionString { get; set; }
protected string User { get; set; }
protected string Pass { get; set; }
protected string ScriptDir { get; set; }
protected bool Overwrite { get; set; }
protected bool Verbose { get; set; }

protected Database CreateDatabase() {
if (!string.IsNullOrEmpty(ConnectionString)) {
if (!string.IsNullOrEmpty(Server) ||
!string.IsNullOrEmpty(DbName) ||
!string.IsNullOrEmpty(User) ||
!string.IsNullOrEmpty(Pass)) {
throw new ConsoleHelpAsException("You must not provide both a connection string and a server/db/user/password");
}
return new Database {
Connection = ConnectionString,
Dir = ScriptDir
};
}
if (string.IsNullOrEmpty(Server) || string.IsNullOrEmpty(DbName)) {
throw new ConsoleHelpAsException("You must provide a connection string, or a server and database name");
}

var builder = new SqlConnectionStringBuilder {
DataSource = Server,
InitialCatalog = DbName,
Expand Down

0 comments on commit 548faf1

Please sign in to comment.