Skip to content
This repository has been archived by the owner on Mar 1, 2021. It is now read-only.

Commit

Permalink
refactor: change Command.Verbosity to an enum
Browse files Browse the repository at this point in the history
  • Loading branch information
adamralph committed Nov 21, 2014
1 parent c686f10 commit 48745e6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/Bau.NuGet/Bau.NuGet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<Compile Include="..\CommonAssemblyInfo.cs">
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Verbosity.cs" />
<Compile Include="Guard.cs" />
<Compile Include="Command.cs" />
<Compile Include="Pack.cs" />
Expand Down
8 changes: 4 additions & 4 deletions src/Bau.NuGet/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected Command()

public string NuGetExePathOverride { get; set; }

public string Verbosity { get; set; }
public Verbosity? Verbosity { get; set; }

public bool NonInteractive { get; set; }

Expand All @@ -33,18 +33,18 @@ public IEnumerable<string> CreateCommandLineArguments()
yield return argument;
}

if (!string.IsNullOrWhiteSpace(this.Verbosity))
if (this.Verbosity.HasValue)
{
// NOTE: Verbose is a valid flag but it is deprecated in favor of Verbosity and should not be used
yield return "-Verbosity " + this.Verbosity;
yield return "-Verbosity " + this.Verbosity.ToString().ToLowerInvariant();
}

if (this.NonInteractive)
{
yield return "-NonInteractive";
}

if (!string.IsNullOrWhiteSpace(this.ConfigFile))
if (this.ConfigFile != null)
{
yield return "-ConfigFile " + this.QuoteWrapCliValue(this.ConfigFile);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Bau.NuGet/CommandExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ public static T WithNuGetExePathOverride<T>(this T command, string nugetExePath)
return command;
}

public static T WithVerbosity<T>(this T command, string verbosity) where T : Command
public static T WithVerbosity<T>(this T command, Verbosity? verbosity) where T : Command
{
command.Verbosity = verbosity;
return command;
}

public static T WithVerbosityDetailed<T>(this T command) where T : Command
{
return command.WithVerbosity("detailed");
return command.WithVerbosity(Verbosity.Detailed);
}

public static T WithVerbosityQuiet<T>(this T command) where T : Command
{
return command.WithVerbosity("quiet");
return command.WithVerbosity(Verbosity.Quiet);
}

public static T WithVerbosityNormal<T>(this T command) where T : Command
{
return command.WithVerbosity("normal");
return command.WithVerbosity(Verbosity.Normal);
}

public static T WithInteraction<T>(this T command) where T : Command
Expand Down
13 changes: 13 additions & 0 deletions src/Bau.NuGet/Verbosity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// <copyright file="Verbosity.cs" company="Bau contributors">
// Copyright (c) Bau contributors. (baubuildch@gmail.com)
// </copyright>

namespace BauNuGet
{
public enum Verbosity
{
Normal,
Quiet,
Detailed,
}
}
19 changes: 8 additions & 11 deletions src/test/Bau.NuGet.Test.Unit/CommandFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public static void DoesNotCreateVerbosityArgumentWhenNotSpecified()
}

[Theory]
[InlineData("normal")]
[InlineData("quiet")]
[InlineData("detailed")]
public static void CreatesVerbosityArgumentWhenSpecified(string verbosity)
[InlineData(Verbosity.Normal)]
[InlineData(Verbosity.Quiet)]
[InlineData(Verbosity.Detailed)]
public static void CreatesVerbosityArgumentWhenSpecified(Verbosity verbosity)
{
// arrange
var command = new DummyCommand { Verbosity = verbosity };
Expand All @@ -39,29 +39,26 @@ public static void CreatesVerbosityArgumentWhenSpecified(string verbosity)
var arguments = command.CreateCommandLineArguments().ToArray();

// assert
arguments.Should().Contain("-Verbosity " + verbosity);
arguments.Should().Contain("-Verbosity " + verbosity.ToString().ToLowerInvariant());
}

[Fact]
public static void PropertyVerbosityFluent()
{
// arrange
var command = new DummyCommand();
var normal = new DummyCommand();
var quiet = new DummyCommand();
var detailed = new DummyCommand();

// act
command.WithVerbosity("Grumbling");
normal.WithVerbosityNormal();
quiet.WithVerbosityQuiet();
detailed.WithVerbosityDetailed();

// assert
command.Verbosity.Should().Be("Grumbling");
Assert.Equal("Normal", normal.Verbosity, StringComparer.OrdinalIgnoreCase);
Assert.Equal("Quiet", quiet.Verbosity, StringComparer.OrdinalIgnoreCase);
Assert.Equal("Detailed", detailed.Verbosity, StringComparer.OrdinalIgnoreCase);
normal.Verbosity.Should().Be(Verbosity.Normal);
quiet.Verbosity.Should().Be(Verbosity.Quiet);
detailed.Verbosity.Should().Be(Verbosity.Detailed);
}

[Fact]
Expand Down

0 comments on commit 48745e6

Please sign in to comment.