diff --git a/CliFx.Tests.Dummy/CliFx.Tests.Dummy.csproj b/CliFx.Tests.Dummy/CliFx.Tests.Dummy.csproj
deleted file mode 100644
index 961f3d4..0000000
--- a/CliFx.Tests.Dummy/CliFx.Tests.Dummy.csproj
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
- Exe
- net46
- 1.2.3.4
- latest
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/CliFx.Tests.Dummy/Commands/GreeterCommand.cs b/CliFx.Tests.Dummy/Commands/GreeterCommand.cs
deleted file mode 100644
index f4c4558..0000000
--- a/CliFx.Tests.Dummy/Commands/GreeterCommand.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using System.Text;
-using System.Threading.Tasks;
-using CliFx.Attributes;
-using CliFx.Services;
-
-namespace CliFx.Tests.Dummy.Commands
-{
- [Command]
- public class GreeterCommand : ICommand
- {
- [CommandOption("target", 't', Description = "Greeting target.")]
- public string Target { get; set; } = "world";
-
- [CommandOption('e', Description = "Whether the greeting should be exclaimed.")]
- public bool IsExclaimed { get; set; }
-
- public Task ExecuteAsync(IConsole console)
- {
- var buffer = new StringBuilder();
-
- buffer.Append("Hello").Append(' ').Append(Target);
-
- if (IsExclaimed)
- buffer.Append('!');
-
- console.Output.WriteLine(buffer.ToString());
-
- return Task.CompletedTask;
- }
- }
-}
\ No newline at end of file
diff --git a/CliFx.Tests.Dummy/Commands/LogCommand.cs b/CliFx.Tests.Dummy/Commands/LogCommand.cs
deleted file mode 100644
index ddfb20c..0000000
--- a/CliFx.Tests.Dummy/Commands/LogCommand.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using CliFx.Attributes;
-using CliFx.Services;
-
-namespace CliFx.Tests.Dummy.Commands
-{
- [Command("log", Description = "Calculate the logarithm of a value.")]
- public class LogCommand : ICommand
- {
- [CommandOption("value", 'v', IsRequired = true, Description = "Value whose logarithm is to be found.")]
- public double Value { get; set; }
-
- [CommandOption("base", 'b', Description = "Logarithm base.")]
- public double Base { get; set; } = 10;
-
- public Task ExecuteAsync(IConsole console)
- {
- var result = Math.Log(Value, Base);
- console.Output.WriteLine(result);
-
- return Task.CompletedTask;
- }
- }
-}
\ No newline at end of file
diff --git a/CliFx.Tests.Dummy/Commands/SumCommand.cs b/CliFx.Tests.Dummy/Commands/SumCommand.cs
deleted file mode 100644
index e0d3e59..0000000
--- a/CliFx.Tests.Dummy/Commands/SumCommand.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using CliFx.Attributes;
-using CliFx.Services;
-
-namespace CliFx.Tests.Dummy.Commands
-{
- [Command("sum", Description = "Calculate the sum of all input values.")]
- public class SumCommand : ICommand
- {
- [CommandOption("values", 'v', IsRequired = true, Description = "Input values.")]
- public IReadOnlyList Values { get; set; }
-
- public Task ExecuteAsync(IConsole console)
- {
- var result = Values.Sum();
- console.Output.WriteLine(result);
-
- return Task.CompletedTask;
- }
- }
-}
\ No newline at end of file
diff --git a/CliFx.Tests.Dummy/Program.cs b/CliFx.Tests.Dummy/Program.cs
deleted file mode 100644
index 3c67d48..0000000
--- a/CliFx.Tests.Dummy/Program.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System.Globalization;
-using System.Threading.Tasks;
-
-namespace CliFx.Tests.Dummy
-{
- public static class Program
- {
- public static Task Main(string[] args)
- {
- // Set culture to invariant to maintain consistent format because we rely on it in tests
- CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
- CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
-
- return new CliApplicationBuilder()
- .AddCommandsFromThisAssembly()
- .UseDescription("Dummy program used for E2E tests.")
- .Build()
- .RunAsync(args);
- }
- }
-}
\ No newline at end of file
diff --git a/CliFx.Tests/CliApplicationBuilderTests.cs b/CliFx.Tests/CliApplicationBuilderTests.cs
index 190fe11..2acca84 100644
--- a/CliFx.Tests/CliApplicationBuilderTests.cs
+++ b/CliFx.Tests/CliApplicationBuilderTests.cs
@@ -8,11 +8,10 @@ namespace CliFx.Tests
[TestFixture]
public partial class CliApplicationBuilderTests
{
+ // Make sure all builder methods work
[Test]
public void Build_Smoke_Test()
{
- // Just test that application can be built after calling all methods
-
// Arrange
var builder = new CliApplicationBuilder();
@@ -33,5 +32,16 @@ namespace CliFx.Tests
.UseCommandFactory(schema => (ICommand) Activator.CreateInstance(schema.Type))
.Build();
}
+
+ // Make sure builder can produce a default application
+ [Test]
+ public void Build_Fallback_Smoke_Test()
+ {
+ // Arrange
+ var builder = new CliApplicationBuilder();
+
+ // Act
+ builder.Build();
+ }
}
}
\ No newline at end of file
diff --git a/CliFx.Tests/CliFx.Tests.csproj b/CliFx.Tests/CliFx.Tests.csproj
index 8e3f228..354489b 100644
--- a/CliFx.Tests/CliFx.Tests.csproj
+++ b/CliFx.Tests/CliFx.Tests.csproj
@@ -15,7 +15,6 @@
-
all
runtime; build; native; contentfiles; analyzers; buildtransitive
@@ -23,7 +22,6 @@
-
diff --git a/CliFx.Tests/DummyTests.cs b/CliFx.Tests/DummyTests.cs
deleted file mode 100644
index e1fe254..0000000
--- a/CliFx.Tests/DummyTests.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-using System.Threading.Tasks;
-using CliWrap;
-using FluentAssertions;
-using NUnit.Framework;
-
-namespace CliFx.Tests
-{
- [TestFixture]
- public class DummyTests
- {
- private static string DummyFilePath => typeof(Dummy.Program).Assembly.Location;
-
- private static string DummyVersionText => $"v{typeof(Dummy.Program).Assembly.GetName().Version}";
-
- [Test]
- [TestCase("", "Hello world")]
- [TestCase("-t .NET", "Hello .NET")]
- [TestCase("-e", "Hello world!")]
- [TestCase("sum -v 1 2", "3")]
- [TestCase("sum -v 2.75 3.6 4.18", "10.53")]
- [TestCase("sum -v 4 -v 16", "20")]
- [TestCase("sum --values 2 5 --values 3", "10")]
- [TestCase("log -v 100", "2")]
- [TestCase("log --value 256 --base 2", "8")]
- public async Task CliApplication_RunAsync_Test(string arguments, string expectedOutput)
- {
- // Arrange & Act
- var result = await Cli.Wrap(DummyFilePath)
- .SetArguments(arguments)
- .EnableExitCodeValidation()
- .EnableStandardErrorValidation()
- .ExecuteAsync();
-
- // Assert
- result.StandardOutput.Trim().Should().Be(expectedOutput);
- }
-
- [Test]
- [TestCase("--version")]
- public async Task CliApplication_RunAsync_ShowVersion_Test(string arguments)
- {
- // Arrange & Act
- var result = await Cli.Wrap(DummyFilePath)
- .SetArguments(arguments)
- .EnableExitCodeValidation()
- .EnableStandardErrorValidation()
- .ExecuteAsync();
-
- // Assert
- result.StandardOutput.Trim().Should().Be(DummyVersionText);
- }
-
- [Test]
- [TestCase("--help")]
- [TestCase("-h")]
- [TestCase("sum -h")]
- [TestCase("sum --help")]
- [TestCase("log -h")]
- [TestCase("log --help")]
- public async Task CliApplication_RunAsync_ShowHelp_Test(string arguments)
- {
- // Arrange & Act
- var result = await Cli.Wrap(DummyFilePath)
- .SetArguments(arguments)
- .EnableExitCodeValidation()
- .EnableStandardErrorValidation()
- .ExecuteAsync();
-
- // Assert
- result.StandardOutput.Trim().Should().NotBeNullOrWhiteSpace();
- }
- }
-}
\ No newline at end of file
diff --git a/CliFx.Tests/Services/SystemConsoleTests.cs b/CliFx.Tests/Services/SystemConsoleTests.cs
new file mode 100644
index 0000000..0f52fa9
--- /dev/null
+++ b/CliFx.Tests/Services/SystemConsoleTests.cs
@@ -0,0 +1,33 @@
+using System;
+using CliFx.Services;
+using FluentAssertions;
+using NUnit.Framework;
+
+namespace CliFx.Tests.Services
+{
+ [TestFixture]
+ public class SystemConsoleTests
+ {
+ // Test that it correctly wraps around System.Console
+ [Test]
+ public void All_Smoke_Test()
+ {
+ // Arrange
+ var console = new SystemConsole();
+
+ console.ResetColor();
+ console.ForegroundColor = ConsoleColor.DarkMagenta;
+ console.BackgroundColor = ConsoleColor.DarkMagenta;
+
+ // Assert
+ console.Input.Should().BeSameAs(Console.In);
+ console.IsInputRedirected.Should().Be(Console.IsInputRedirected);
+ console.Output.Should().BeSameAs(Console.Out);
+ console.IsOutputRedirected.Should().Be(Console.IsOutputRedirected);
+ console.Error.Should().BeSameAs(Console.Error);
+ console.IsErrorRedirected.Should().Be(Console.IsErrorRedirected);
+ console.ForegroundColor.Should().Be(Console.ForegroundColor);
+ console.BackgroundColor.Should().Be(Console.BackgroundColor);
+ }
+ }
+}
\ No newline at end of file
diff --git a/CliFx.sln b/CliFx.sln
index 62051c1..c896a26 100644
--- a/CliFx.sln
+++ b/CliFx.sln
@@ -7,8 +7,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CliFx", "CliFx\CliFx.csproj
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CliFx.Tests", "CliFx.Tests\CliFx.Tests.csproj", "{268CF863-65A5-49BB-93CF-08972B7756DC}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CliFx.Tests.Dummy", "CliFx.Tests.Dummy\CliFx.Tests.Dummy.csproj", "{4904B3EB-3286-4F1B-8B74-6FF051C8E787}"
-EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3AAE8166-BB8E-49DA-844C-3A0EE6BD40A0}"
ProjectSection(SolutionItems) = preProject
Changelog.md = Changelog.md
@@ -18,7 +16,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CliFx.Benchmarks", "CliFx.Benchmarks\CliFx.Benchmarks.csproj", "{8ACD6DC2-D768-4850-9223-5B7C83A78513}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CliFx.Demo", "CliFx.Demo\CliFx.Demo.csproj", "{AAB6844C-BF71-448F-A11B-89AEE459AB15}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CliFx.Demo", "CliFx.Demo\CliFx.Demo.csproj", "{AAB6844C-BF71-448F-A11B-89AEE459AB15}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -54,18 +52,6 @@ Global
{268CF863-65A5-49BB-93CF-08972B7756DC}.Release|x64.Build.0 = Release|Any CPU
{268CF863-65A5-49BB-93CF-08972B7756DC}.Release|x86.ActiveCfg = Release|Any CPU
{268CF863-65A5-49BB-93CF-08972B7756DC}.Release|x86.Build.0 = Release|Any CPU
- {4904B3EB-3286-4F1B-8B74-6FF051C8E787}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {4904B3EB-3286-4F1B-8B74-6FF051C8E787}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {4904B3EB-3286-4F1B-8B74-6FF051C8E787}.Debug|x64.ActiveCfg = Debug|Any CPU
- {4904B3EB-3286-4F1B-8B74-6FF051C8E787}.Debug|x64.Build.0 = Debug|Any CPU
- {4904B3EB-3286-4F1B-8B74-6FF051C8E787}.Debug|x86.ActiveCfg = Debug|Any CPU
- {4904B3EB-3286-4F1B-8B74-6FF051C8E787}.Debug|x86.Build.0 = Debug|Any CPU
- {4904B3EB-3286-4F1B-8B74-6FF051C8E787}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {4904B3EB-3286-4F1B-8B74-6FF051C8E787}.Release|Any CPU.Build.0 = Release|Any CPU
- {4904B3EB-3286-4F1B-8B74-6FF051C8E787}.Release|x64.ActiveCfg = Release|Any CPU
- {4904B3EB-3286-4F1B-8B74-6FF051C8E787}.Release|x64.Build.0 = Release|Any CPU
- {4904B3EB-3286-4F1B-8B74-6FF051C8E787}.Release|x86.ActiveCfg = Release|Any CPU
- {4904B3EB-3286-4F1B-8B74-6FF051C8E787}.Release|x86.Build.0 = Release|Any CPU
{8ACD6DC2-D768-4850-9223-5B7C83A78513}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8ACD6DC2-D768-4850-9223-5B7C83A78513}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8ACD6DC2-D768-4850-9223-5B7C83A78513}.Debug|x64.ActiveCfg = Debug|Any CPU
diff --git a/CliFx/CliApplicationBuilder.cs b/CliFx/CliApplicationBuilder.cs
index 092bcdc..6fd5cfd 100644
--- a/CliFx/CliApplicationBuilder.cs
+++ b/CliFx/CliApplicationBuilder.cs
@@ -108,59 +108,15 @@ namespace CliFx
return this;
}
- private void SetFallbackValues()
- {
- if (_title.IsNullOrWhiteSpace())
- {
- UseTitle(EntryAssembly?.GetName().Name ?? "App");
- }
-
- if (_executableName.IsNullOrWhiteSpace())
- {
- var entryAssemblyLocation = EntryAssembly?.Location;
-
- // Set different executable name depending on location
- if (!entryAssemblyLocation.IsNullOrWhiteSpace())
- {
- // Prepend 'dotnet' to assembly file name if the entry assembly is a dll file (extension needs to be kept)
- if (string.Equals(Path.GetExtension(entryAssemblyLocation), ".dll", StringComparison.OrdinalIgnoreCase))
- {
- UseExecutableName("dotnet " + Path.GetFileName(entryAssemblyLocation));
- }
- // Otherwise just use assembly file name without extension
- else
- {
- UseExecutableName(Path.GetFileNameWithoutExtension(entryAssemblyLocation));
- }
- }
- // If location is null then just use a stub
- else
- {
- UseExecutableName("app");
- }
- }
-
- if (_versionText.IsNullOrWhiteSpace())
- {
- UseVersionText(EntryAssembly != null ? $"v{EntryAssembly.GetName().Version}" : "v1.0");
- }
-
- if (_console == null)
- {
- UseConsole(new SystemConsole());
- }
-
- if (_commandFactory == null)
- {
- UseCommandFactory(new CommandFactory());
- }
- }
-
///
public ICliApplication Build()
{
// Use defaults for required parameters that were not configured
- SetFallbackValues();
+ _title = _title ?? GetDefaultTitle() ?? "App";
+ _executableName = _executableName ?? GetDefaultExecutableName() ?? "app";
+ _versionText = _versionText ?? GetDefaultVersionText() ?? "v1.0";
+ _console = _console ?? new SystemConsole();
+ _commandFactory = _commandFactory ?? new CommandFactory();
// Project parameters to expected types
var metadata = new ApplicationMetadata(_title, _executableName, _versionText, _description);
@@ -178,5 +134,23 @@ namespace CliFx
// Entry assembly is null in tests
private static Assembly EntryAssembly => LazyEntryAssembly.Value;
+
+ private static string GetDefaultTitle() => EntryAssembly?.GetName().Name;
+
+ private static string GetDefaultExecutableName()
+ {
+ var entryAssemblyLocation = EntryAssembly?.Location;
+
+ // If it's a .dll assembly, prepend 'dotnet' and keep the file extension
+ if (string.Equals(Path.GetExtension(entryAssemblyLocation), ".dll", StringComparison.OrdinalIgnoreCase))
+ {
+ return "dotnet " + Path.GetFileName(entryAssemblyLocation);
+ }
+
+ // Otherwise just use assembly file name without extension
+ return Path.GetFileNameWithoutExtension(entryAssemblyLocation);
+ }
+
+ private static string GetDefaultVersionText() => EntryAssembly != null ? $"v{EntryAssembly.GetName().Version}" : null;
}
}
\ No newline at end of file
diff --git a/Readme.md b/Readme.md
index eda7459..b17e111 100644
--- a/Readme.md
+++ b/Readme.md
@@ -426,7 +426,6 @@ CliFx is made out of "Cli" for "Command Line Interface" and "Fx" for "Framework"
## Libraries used
- [NUnit](https://github.com/nunit/nunit)
-- [CliWrap](https://github.com/Tyrrrz/CliWrap)
- [FluentAssertions](https://github.com/fluentassertions/fluentassertions)
- [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json)
- [BenchmarkDotNet](https://github.com/dotnet/BenchmarkDotNet)