Skip to content

Commit

Permalink
Merge pull request #17 from drwatson1/bug/issue15
Browse files Browse the repository at this point in the history
Bug/issue15 resolved
  • Loading branch information
drwatson1 committed Jan 29, 2022
2 parents f9cb15b + 618b37a commit 42bf69d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ The tool has almost all the features the DbUp has, but without a single line of

|Date|Version|Description|
|-|-|-|
|2022-01-29|1.6.1|BUGFIX: 'version' and '--version' should return exit code 0
|2021-10-03|1.6.0|Add a 'journalTo' option to dbup.yml
|2021-03-28|1.5.0|Add support of .Net Core 3.1 and .Net 5.0
|2021-03-27|1.4.0|Add script naming options<BR>Load .env.local after .env
Expand Down
13 changes: 12 additions & 1 deletion src/dbup-cli.tests/ToolEngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ public void InitCommand_ShouldReturn1AndNotCreateConfig_IfItIsPresent()
saved.Should().BeFalse();
}

[TestMethod]
public void VersionCommand_ShouldReturnZero()
{
var env = A.Fake<IEnvironment>();
var engine = new ToolEngine(env, A.Fake<IUpgradeLog>());

var exit_code = engine.Run("version");

exit_code.Should().Be(0);
}

[TestMethod]
public void StatusCommand_ShouldPrintGeneralInformation_IfNoScriptsToExecute()
{
Expand Down Expand Up @@ -126,7 +137,7 @@ public void StatusCommand_ShouldUseSpecifiedEnvFiles()

var engine = new ToolEngine(env, Logger, (testConnectionFactory as IConnectionFactory).Some());

var result = engine.Run("status", GetConfigPath("Status/status.yml"), "-n",
var result = engine.Run("status", GetConfigPath("Status/status.yml"), "-n",
"--env", GetConfigPath("Status/file1.env"), GetConfigPath("Status/file2.env"));

Logger.InfoMessages.Last().Should().EndWith("c001.sql");
Expand Down
21 changes: 20 additions & 1 deletion src/dbup-cli/ToolEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,30 @@ public int Run(params string[] args) =>
(MarkAsExecutedOptions opts) => WrapException(() => RunMarkAsExecutedCommand(opts)),
(DropOptions opts) => WrapException(() => RunDropCommand(opts)),
(StatusOptions opts) => WrapException(() => RunStatusCommand(opts)),
(parserErrors) => Option.None<int, Error>(Error.Create("")))
(parseErrors) => WrapException(() => ParseErrors(parseErrors)))
.Match(
some: x => x,
none: error => { Console.WriteLine(error.Message); return 1; });

private Option<int, Error> ParseErrors(IEnumerable<CommandLine.Error> parseErrors)
{
foreach (var err in parseErrors)
{
if (err.StopsProcessing)
{
// Autoimplemented verbs and params
switch (err.Tag)
{
case ErrorType.VersionRequestedError:
case ErrorType.HelpRequestedError:
case ErrorType.HelpVerbRequestedError:
return Option.Some<int, Error>(0);
}
}
}
return Option.None<int, Error>(Error.Create(""));
}

private Option<int, Error> RunStatusCommand(StatusOptions opts) =>
ConfigurationHelper.LoadEnvironmentVariables(Environment, opts.File, opts.EnvFiles)
.Match(
Expand Down
6 changes: 3 additions & 3 deletions src/dbup-cli/dbup-cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
<LangVersion>latest</LangVersion>
<Product>DbUp Command Line Interface</Product>
<Authors>Sergey Tregub</Authors>
<Version>1.6.0</Version>
<Version>1.6.1</Version>
<RepositoryUrl>https://github.com/drwatson1/dbup-cli</RepositoryUrl>
<Company />
<Copyright>Copyright (c) 2021 Sergey Tregub</Copyright>
<Copyright>Copyright (c) 2022 Sergey Tregub</Copyright>
<PackageProjectUrl>https://github.com/drwatson1/dbup-cli</PackageProjectUrl>
<RepositoryType>GitHub</RepositoryType>
<PackageTags>dbup database migration sqlserver postgresql mysql</PackageTags>
<PackAsTool>true</PackAsTool>
<ToolCommandName>dbup</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
<PackageReleaseNotes>Add a 'journalTo' option to dbup.yml</PackageReleaseNotes>
<PackageReleaseNotes>BUGFIX: 'version' and '--version' should return exit code 0</PackageReleaseNotes>
<Title>DbUp Command Line Interface</Title>
<Description>Command line tool, that can be installed as a .Net global tool, that helps you to deploy changes to databases. It tracks which SQL scripts have been run already, and runs the change scripts that are needed to get your database up to date.</Description>
<PackageLicenseUrl></PackageLicenseUrl>
Expand Down

0 comments on commit 42bf69d

Please sign in to comment.