From 7d29a60af5da7234e722b1e283d5ef3fb238c97d Mon Sep 17 00:00:00 2001 From: Jeff Tong Date: Tue, 14 Aug 2018 15:08:31 -0700 Subject: [PATCH 01/18] Proposed changes for enhancement: https://github.com/commandlineparser/commandline/issues/189 --- paket.lock | 420 +++++++++--------- src/CommandLine/CommandLine.csproj | 12 +- src/CommandLine/Core/ReflectionExtensions.cs | 9 +- src/CommandLine/Error.cs | 21 +- .../CommandLine.Tests.Properties.csproj | 32 +- .../CommandLine.Tests.csproj | 37 +- .../Fakes/Options_With_InvalidDefaults.cs | 11 + .../Unit/Core/InstanceBuilderTests.cs | 15 + 8 files changed, 313 insertions(+), 244 deletions(-) create mode 100644 tests/CommandLine.Tests/Fakes/Options_With_InvalidDefaults.cs diff --git a/paket.lock b/paket.lock index a2282355..930a9e1c 100644 --- a/paket.lock +++ b/paket.lock @@ -2,22 +2,22 @@ NUGET remote: https://www.nuget.org/api/v2 FAKE (4.3.4) FluentAssertions (4.0) - System.Collections (>= 4.0.10) - framework: dnxcore50 - System.Diagnostics.Debug (>= 4.0.10) - framework: dnxcore50 - System.Globalization (>= 4.0.10) - framework: dnxcore50 - System.Linq (>= 4.0) - framework: dnxcore50 - System.Linq.Expressions (>= 4.0.10) - framework: dnxcore50 - System.ObjectModel (>= 4.0.10) - framework: dnxcore50 - System.Reflection (>= 4.0.10) - framework: dnxcore50 - System.Reflection.Extensions (>= 4.0) - framework: dnxcore50 - System.Reflection.Primitives (>= 4.0) - framework: dnxcore50 - System.Reflection.TypeExtensions (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0.10) - framework: dnxcore50 - System.Text.RegularExpressions (>= 4.0.10) - framework: dnxcore50 - System.Threading (>= 4.0.10) - framework: dnxcore50 - System.Threading.Tasks (>= 4.0.10) - framework: dnxcore50 - System.Xml.XDocument (>= 4.0.10) - framework: dnxcore50 + System.Collections (>= 4.0.10) - restriction: == dnxcore50 + System.Diagnostics.Debug (>= 4.0.10) - restriction: == dnxcore50 + System.Globalization (>= 4.0.10) - restriction: == dnxcore50 + System.Linq (>= 4.0) - restriction: == dnxcore50 + System.Linq.Expressions (>= 4.0.10) - restriction: == dnxcore50 + System.ObjectModel (>= 4.0.10) - restriction: == dnxcore50 + System.Reflection (>= 4.0.10) - restriction: == dnxcore50 + System.Reflection.Extensions (>= 4.0) - restriction: == dnxcore50 + System.Reflection.Primitives (>= 4.0) - restriction: == dnxcore50 + System.Reflection.TypeExtensions (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0.20) - restriction: == dnxcore50 + System.Runtime.Extensions (>= 4.0.10) - restriction: == dnxcore50 + System.Text.RegularExpressions (>= 4.0.10) - restriction: == dnxcore50 + System.Threading (>= 4.0.10) - restriction: == dnxcore50 + System.Threading.Tasks (>= 4.0.10) - restriction: == dnxcore50 + System.Xml.XDocument (>= 4.0.10) - restriction: == dnxcore50 FsCheck (2.0.7) FSharp.Core (>= 3.1.2.5) FSharp.Compiler.Service (1.4.0.1) @@ -27,200 +27,200 @@ NUGET FSharpVSPowerTools.Core (1.8) FSharpVSPowerTools.Core (1.8) FSharp.Compiler.Service (>= 0.0.87) - System.Collections (4.0.10) - framework: dnxcore50 - System.Diagnostics.Debug (>= 4.0) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0) - framework: dnxcore50 - System.Threading (>= 4.0) - framework: dnxcore50 - System.Diagnostics.Contracts (4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Diagnostics.Debug (4.0.10) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Globalization (4.0.10) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.IO (4.0.10) - framework: dnxcore50 - System.Globalization (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Text.Encoding (>= 4.0) - framework: dnxcore50 - System.Text.Encoding (>= 4.0.10) - framework: dnxcore50 - System.Text.Encoding.Extensions (>= 4.0) - framework: dnxcore50 - System.Threading (>= 4.0) - framework: dnxcore50 - System.Threading.Tasks (>= 4.0) - framework: dnxcore50 - System.IO.FileSystem (4.0) - framework: dnxcore50 - System.Collections (>= 4.0.10) - framework: dnxcore50 - System.Diagnostics.Debug (>= 4.0.10) - framework: dnxcore50 - System.IO (>= 4.0) - framework: dnxcore50 - System.IO (>= 4.0.10) - framework: dnxcore50 - System.IO.FileSystem.Primitives (>= 4.0) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0.10) - framework: dnxcore50 - System.Runtime.Handles (>= 4.0) - framework: dnxcore50 - System.Runtime.InteropServices (>= 4.0.20) - framework: dnxcore50 - System.Runtime.WindowsRuntime (>= 4.0) - framework: dnxcore50 - System.Text.Encoding (>= 4.0) - framework: dnxcore50 - System.Text.Encoding (>= 4.0.10) - framework: dnxcore50 - System.Text.Encoding.Extensions (>= 4.0.10) - framework: dnxcore50 - System.Threading (>= 4.0.10) - framework: dnxcore50 - System.Threading.Overlapped (>= 4.0) - framework: dnxcore50 - System.Threading.Tasks (>= 4.0) - framework: dnxcore50 - System.Threading.Tasks (>= 4.0.10) - framework: dnxcore50 - System.IO.FileSystem.Primitives (4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Linq (4.0) - framework: dnxcore50 - System.Collections (>= 4.0.10) - framework: dnxcore50 - System.Diagnostics.Debug (>= 4.0.10) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0.10) - framework: dnxcore50 - System.Linq.Expressions (4.0.10) - framework: dnxcore50 - System.Collections (>= 4.0) - framework: dnxcore50 - System.Diagnostics.Debug (>= 4.0) - framework: dnxcore50 - System.Globalization (>= 4.0) - framework: dnxcore50 - System.IO (>= 4.0) - framework: dnxcore50 - System.Linq (>= 4.0) - framework: dnxcore50 - System.ObjectModel (>= 4.0) - framework: dnxcore50 - System.Reflection (>= 4.0) - framework: dnxcore50 - System.Reflection.Emit (>= 4.0) - framework: dnxcore50 - System.Reflection.Extensions (>= 4.0) - framework: dnxcore50 - System.Reflection.Primitives (>= 4.0) - framework: dnxcore50 - System.Reflection.TypeExtensions (>= 4.0) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0) - framework: dnxcore50 - System.Threading (>= 4.0) - framework: dnxcore50 - System.ObjectModel (4.0.10) - framework: dnxcore50 - System.Collections (>= 4.0.10) - framework: dnxcore50 - System.Diagnostics.Debug (>= 4.0.10) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Threading (>= 4.0.10) - framework: dnxcore50 - System.Private.Uri (4.0) - framework: dnxcore50 - System.Reflection (4.0.10) - framework: dnxcore50 - System.IO (>= 4.0) - framework: dnxcore50 - System.Reflection.Primitives (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Reflection.Emit (4.0) - framework: dnxcore50 - System.IO (>= 4.0) - framework: dnxcore50 - System.Reflection (>= 4.0) - framework: dnxcore50 - System.Reflection.Emit.ILGeneration (>= 4.0) - framework: dnxcore50 - System.Reflection.Primitives (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Reflection.Emit.ILGeneration (4.0) - framework: dnxcore50 - System.Reflection (>= 4.0) - framework: dnxcore50 - System.Reflection.Primitives (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Reflection.Extensions (4.0) - framework: dnxcore50 - System.Diagnostics.Debug (>= 4.0.10) - framework: dnxcore50 - System.Reflection (>= 4.0) - framework: dnxcore50 - System.Reflection (>= 4.0.10) - framework: dnxcore50 - System.Reflection.Primitives (>= 4.0) - framework: dnxcore50 - System.Reflection.TypeExtensions (>= 4.0) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0.10) - framework: dnxcore50 - System.Reflection.Primitives (4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Threading (>= 4.0) - framework: dnxcore50 - System.Reflection.TypeExtensions (4.0) - framework: dnxcore50 - System.Diagnostics.Contracts (>= 4.0) - framework: dnxcore50 - System.Diagnostics.Debug (>= 4.0.10) - framework: dnxcore50 - System.Linq (>= 4.0) - framework: dnxcore50 - System.Reflection (>= 4.0) - framework: dnxcore50 - System.Reflection (>= 4.0.10) - framework: dnxcore50 - System.Reflection.Primitives (>= 4.0) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0.10) - framework: dnxcore50 - System.Resources.ResourceManager (4.0) - framework: dnxcore50 - System.Globalization (>= 4.0) - framework: dnxcore50 - System.Reflection (>= 4.0) - framework: dnxcore50 - System.Reflection (>= 4.0.10) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime (4.0.20) - framework: dnxcore50 - System.Private.Uri (>= 4.0) - framework: dnxcore50 - System.Runtime.Extensions (4.0.10) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Handles (4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Runtime.InteropServices (4.0.20) - framework: dnxcore50 - System.Reflection (>= 4.0) - framework: dnxcore50 - System.Reflection.Primitives (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Runtime.Handles (>= 4.0) - framework: dnxcore50 - System.Runtime.WindowsRuntime (4.0.10) - framework: dnxcore50 - System.Diagnostics.Debug (>= 4.0.10) - framework: dnxcore50 - System.Globalization (>= 4.0) - framework: dnxcore50 - System.IO (>= 4.0) - framework: dnxcore50 - System.IO (>= 4.0.10) - framework: dnxcore50 - System.ObjectModel (>= 4.0) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0) - framework: dnxcore50 - System.Runtime.InteropServices (>= 4.0.20) - framework: dnxcore50 - System.Threading (>= 4.0.10) - framework: dnxcore50 - System.Threading.Tasks (>= 4.0) - framework: dnxcore50 - System.Threading.Tasks (>= 4.0.10) - framework: dnxcore50 - System.Text.Encoding (4.0.10) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Text.Encoding.Extensions (4.0.10) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Text.Encoding (>= 4.0.10) - framework: dnxcore50 - System.Text.RegularExpressions (4.0.10) - framework: dnxcore50 - System.Collections (>= 4.0.10) - framework: dnxcore50 - System.Globalization (>= 4.0.10) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0.10) - framework: dnxcore50 - System.Threading (>= 4.0.10) - framework: dnxcore50 - System.Threading (4.0.10) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Threading.Tasks (>= 4.0) - framework: dnxcore50 - System.Threading.Overlapped (4.0) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0) - framework: dnxcore50 - System.Runtime.Handles (>= 4.0) - framework: dnxcore50 - System.Runtime.InteropServices (>= 4.0.20) - framework: dnxcore50 - System.Threading (>= 4.0.10) - framework: dnxcore50 - System.Threading.Tasks (4.0.10) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Xml.ReaderWriter (4.0.10) - framework: dnxcore50 - System.Collections (>= 4.0.10) - framework: dnxcore50 - System.Diagnostics.Debug (>= 4.0.10) - framework: dnxcore50 - System.Globalization (>= 4.0.10) - framework: dnxcore50 - System.IO (>= 4.0.10) - framework: dnxcore50 - System.IO.FileSystem (>= 4.0) - framework: dnxcore50 - System.IO.FileSystem.Primitives (>= 4.0) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0.10) - framework: dnxcore50 - System.Runtime.InteropServices (>= 4.0.20) - framework: dnxcore50 - System.Text.Encoding (>= 4.0.10) - framework: dnxcore50 - System.Text.Encoding.Extensions (>= 4.0.10) - framework: dnxcore50 - System.Text.RegularExpressions (>= 4.0.10) - framework: dnxcore50 - System.Threading.Tasks (>= 4.0.10) - framework: dnxcore50 - System.Xml.XDocument (4.0.10) - framework: dnxcore50 - System.Collections (>= 4.0.10) - framework: dnxcore50 - System.Diagnostics.Debug (>= 4.0.10) - framework: dnxcore50 - System.Globalization (>= 4.0.10) - framework: dnxcore50 - System.IO (>= 4.0.10) - framework: dnxcore50 - System.Reflection (>= 4.0.10) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0.10) - framework: dnxcore50 - System.Text.Encoding (>= 4.0.10) - framework: dnxcore50 - System.Threading (>= 4.0.10) - framework: dnxcore50 - System.Xml.ReaderWriter (>= 4.0.10) - framework: dnxcore50 + System.Collections (4.0.10) - restriction: == dnxcore50 + System.Diagnostics.Debug (>= 4.0) - restriction: == dnxcore50 + System.Resources.ResourceManager (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0.20) - restriction: == dnxcore50 + System.Runtime.Extensions (>= 4.0) - restriction: == dnxcore50 + System.Threading (>= 4.0) - restriction: == dnxcore50 + System.Diagnostics.Contracts (4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Diagnostics.Debug (4.0.10) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Globalization (4.0.10) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.IO (4.0.10) - restriction: == dnxcore50 + System.Globalization (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0.20) - restriction: == dnxcore50 + System.Text.Encoding (>= 4.0) - restriction: == dnxcore50 + System.Text.Encoding (>= 4.0.10) - restriction: == dnxcore50 + System.Text.Encoding.Extensions (>= 4.0) - restriction: == dnxcore50 + System.Threading (>= 4.0) - restriction: == dnxcore50 + System.Threading.Tasks (>= 4.0) - restriction: == dnxcore50 + System.IO.FileSystem (4.0) - restriction: == dnxcore50 + System.Collections (>= 4.0.10) - restriction: == dnxcore50 + System.Diagnostics.Debug (>= 4.0.10) - restriction: == dnxcore50 + System.IO (>= 4.0) - restriction: == dnxcore50 + System.IO (>= 4.0.10) - restriction: == dnxcore50 + System.IO.FileSystem.Primitives (>= 4.0) - restriction: == dnxcore50 + System.Resources.ResourceManager (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0.20) - restriction: == dnxcore50 + System.Runtime.Extensions (>= 4.0.10) - restriction: == dnxcore50 + System.Runtime.Handles (>= 4.0) - restriction: == dnxcore50 + System.Runtime.InteropServices (>= 4.0.20) - restriction: == dnxcore50 + System.Runtime.WindowsRuntime (>= 4.0) - restriction: == dnxcore50 + System.Text.Encoding (>= 4.0) - restriction: == dnxcore50 + System.Text.Encoding (>= 4.0.10) - restriction: == dnxcore50 + System.Text.Encoding.Extensions (>= 4.0.10) - restriction: == dnxcore50 + System.Threading (>= 4.0.10) - restriction: == dnxcore50 + System.Threading.Overlapped (>= 4.0) - restriction: == dnxcore50 + System.Threading.Tasks (>= 4.0) - restriction: == dnxcore50 + System.Threading.Tasks (>= 4.0.10) - restriction: == dnxcore50 + System.IO.FileSystem.Primitives (4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0.20) - restriction: == dnxcore50 + System.Linq (4.0) - restriction: == dnxcore50 + System.Collections (>= 4.0.10) - restriction: == dnxcore50 + System.Diagnostics.Debug (>= 4.0.10) - restriction: == dnxcore50 + System.Resources.ResourceManager (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0.20) - restriction: == dnxcore50 + System.Runtime.Extensions (>= 4.0.10) - restriction: == dnxcore50 + System.Linq.Expressions (4.0.10) - restriction: == dnxcore50 + System.Collections (>= 4.0) - restriction: == dnxcore50 + System.Diagnostics.Debug (>= 4.0) - restriction: == dnxcore50 + System.Globalization (>= 4.0) - restriction: == dnxcore50 + System.IO (>= 4.0) - restriction: == dnxcore50 + System.Linq (>= 4.0) - restriction: == dnxcore50 + System.ObjectModel (>= 4.0) - restriction: == dnxcore50 + System.Reflection (>= 4.0) - restriction: == dnxcore50 + System.Reflection.Emit (>= 4.0) - restriction: == dnxcore50 + System.Reflection.Extensions (>= 4.0) - restriction: == dnxcore50 + System.Reflection.Primitives (>= 4.0) - restriction: == dnxcore50 + System.Reflection.TypeExtensions (>= 4.0) - restriction: == dnxcore50 + System.Resources.ResourceManager (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0.20) - restriction: == dnxcore50 + System.Runtime.Extensions (>= 4.0) - restriction: == dnxcore50 + System.Threading (>= 4.0) - restriction: == dnxcore50 + System.ObjectModel (4.0.10) - restriction: == dnxcore50 + System.Collections (>= 4.0.10) - restriction: == dnxcore50 + System.Diagnostics.Debug (>= 4.0.10) - restriction: == dnxcore50 + System.Resources.ResourceManager (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0.20) - restriction: == dnxcore50 + System.Threading (>= 4.0.10) - restriction: == dnxcore50 + System.Private.Uri (4.0) - restriction: == dnxcore50 + System.Reflection (4.0.10) - restriction: == dnxcore50 + System.IO (>= 4.0) - restriction: == dnxcore50 + System.Reflection.Primitives (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0.20) - restriction: == dnxcore50 + System.Reflection.Emit (4.0) - restriction: == dnxcore50 + System.IO (>= 4.0) - restriction: == dnxcore50 + System.Reflection (>= 4.0) - restriction: == dnxcore50 + System.Reflection.Emit.ILGeneration (>= 4.0) - restriction: == dnxcore50 + System.Reflection.Primitives (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Reflection.Emit.ILGeneration (4.0) - restriction: == dnxcore50 + System.Reflection (>= 4.0) - restriction: == dnxcore50 + System.Reflection.Primitives (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Reflection.Extensions (4.0) - restriction: == dnxcore50 + System.Diagnostics.Debug (>= 4.0.10) - restriction: == dnxcore50 + System.Reflection (>= 4.0) - restriction: == dnxcore50 + System.Reflection (>= 4.0.10) - restriction: == dnxcore50 + System.Reflection.Primitives (>= 4.0) - restriction: == dnxcore50 + System.Reflection.TypeExtensions (>= 4.0) - restriction: == dnxcore50 + System.Resources.ResourceManager (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0.20) - restriction: == dnxcore50 + System.Runtime.Extensions (>= 4.0.10) - restriction: == dnxcore50 + System.Reflection.Primitives (4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Threading (>= 4.0) - restriction: == dnxcore50 + System.Reflection.TypeExtensions (4.0) - restriction: == dnxcore50 + System.Diagnostics.Contracts (>= 4.0) - restriction: == dnxcore50 + System.Diagnostics.Debug (>= 4.0.10) - restriction: == dnxcore50 + System.Linq (>= 4.0) - restriction: == dnxcore50 + System.Reflection (>= 4.0) - restriction: == dnxcore50 + System.Reflection (>= 4.0.10) - restriction: == dnxcore50 + System.Reflection.Primitives (>= 4.0) - restriction: == dnxcore50 + System.Resources.ResourceManager (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0.20) - restriction: == dnxcore50 + System.Runtime.Extensions (>= 4.0.10) - restriction: == dnxcore50 + System.Resources.ResourceManager (4.0) - restriction: == dnxcore50 + System.Globalization (>= 4.0) - restriction: == dnxcore50 + System.Reflection (>= 4.0) - restriction: == dnxcore50 + System.Reflection (>= 4.0.10) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0.20) - restriction: == dnxcore50 + System.Runtime (4.0.20) - restriction: == dnxcore50 + System.Private.Uri (>= 4.0) - restriction: == dnxcore50 + System.Runtime.Extensions (4.0.10) - restriction: == dnxcore50 + System.Runtime (>= 4.0.20) - restriction: == dnxcore50 + System.Runtime.Handles (4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Runtime.InteropServices (4.0.20) - restriction: == dnxcore50 + System.Reflection (>= 4.0) - restriction: == dnxcore50 + System.Reflection.Primitives (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Runtime.Handles (>= 4.0) - restriction: == dnxcore50 + System.Runtime.WindowsRuntime (4.0.10) - restriction: == dnxcore50 + System.Diagnostics.Debug (>= 4.0.10) - restriction: == dnxcore50 + System.Globalization (>= 4.0) - restriction: == dnxcore50 + System.IO (>= 4.0) - restriction: == dnxcore50 + System.IO (>= 4.0.10) - restriction: == dnxcore50 + System.ObjectModel (>= 4.0) - restriction: == dnxcore50 + System.Resources.ResourceManager (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0.20) - restriction: == dnxcore50 + System.Runtime.Extensions (>= 4.0) - restriction: == dnxcore50 + System.Runtime.InteropServices (>= 4.0.20) - restriction: == dnxcore50 + System.Threading (>= 4.0.10) - restriction: == dnxcore50 + System.Threading.Tasks (>= 4.0) - restriction: == dnxcore50 + System.Threading.Tasks (>= 4.0.10) - restriction: == dnxcore50 + System.Text.Encoding (4.0.10) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Text.Encoding.Extensions (4.0.10) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Text.Encoding (>= 4.0.10) - restriction: == dnxcore50 + System.Text.RegularExpressions (4.0.10) - restriction: == dnxcore50 + System.Collections (>= 4.0.10) - restriction: == dnxcore50 + System.Globalization (>= 4.0.10) - restriction: == dnxcore50 + System.Resources.ResourceManager (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0.20) - restriction: == dnxcore50 + System.Runtime.Extensions (>= 4.0.10) - restriction: == dnxcore50 + System.Threading (>= 4.0.10) - restriction: == dnxcore50 + System.Threading (4.0.10) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Threading.Tasks (>= 4.0) - restriction: == dnxcore50 + System.Threading.Overlapped (4.0) - restriction: == dnxcore50 + System.Resources.ResourceManager (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0.20) - restriction: == dnxcore50 + System.Runtime.Extensions (>= 4.0) - restriction: == dnxcore50 + System.Runtime.Handles (>= 4.0) - restriction: == dnxcore50 + System.Runtime.InteropServices (>= 4.0.20) - restriction: == dnxcore50 + System.Threading (>= 4.0.10) - restriction: == dnxcore50 + System.Threading.Tasks (4.0.10) - restriction: == dnxcore50 + System.Runtime (>= 4.0) - restriction: == dnxcore50 + System.Xml.ReaderWriter (4.0.10) - restriction: == dnxcore50 + System.Collections (>= 4.0.10) - restriction: == dnxcore50 + System.Diagnostics.Debug (>= 4.0.10) - restriction: == dnxcore50 + System.Globalization (>= 4.0.10) - restriction: == dnxcore50 + System.IO (>= 4.0.10) - restriction: == dnxcore50 + System.IO.FileSystem (>= 4.0) - restriction: == dnxcore50 + System.IO.FileSystem.Primitives (>= 4.0) - restriction: == dnxcore50 + System.Resources.ResourceManager (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0.20) - restriction: == dnxcore50 + System.Runtime.Extensions (>= 4.0.10) - restriction: == dnxcore50 + System.Runtime.InteropServices (>= 4.0.20) - restriction: == dnxcore50 + System.Text.Encoding (>= 4.0.10) - restriction: == dnxcore50 + System.Text.Encoding.Extensions (>= 4.0.10) - restriction: == dnxcore50 + System.Text.RegularExpressions (>= 4.0.10) - restriction: == dnxcore50 + System.Threading.Tasks (>= 4.0.10) - restriction: == dnxcore50 + System.Xml.XDocument (4.0.10) - restriction: == dnxcore50 + System.Collections (>= 4.0.10) - restriction: == dnxcore50 + System.Diagnostics.Debug (>= 4.0.10) - restriction: == dnxcore50 + System.Globalization (>= 4.0.10) - restriction: == dnxcore50 + System.IO (>= 4.0.10) - restriction: == dnxcore50 + System.Reflection (>= 4.0.10) - restriction: == dnxcore50 + System.Resources.ResourceManager (>= 4.0) - restriction: == dnxcore50 + System.Runtime (>= 4.0.20) - restriction: == dnxcore50 + System.Runtime.Extensions (>= 4.0.10) - restriction: == dnxcore50 + System.Text.Encoding (>= 4.0.10) - restriction: == dnxcore50 + System.Threading (>= 4.0.10) - restriction: == dnxcore50 + System.Xml.ReaderWriter (>= 4.0.10) - restriction: == dnxcore50 xunit (2.0) xunit.assert (2.0) xunit.core (2.0) diff --git a/src/CommandLine/CommandLine.csproj b/src/CommandLine/CommandLine.csproj index 8f829c9f..b52d03b2 100644 --- a/src/CommandLine/CommandLine.csproj +++ b/src/CommandLine/CommandLine.csproj @@ -169,8 +169,16 @@ - - + + + + ..\..\packages\FSharp.Core\lib\net40\FSharp.Core.dll + True + True + + + + ..\..\packages\FSharp.Core\lib\portable-net45+netcore45\FSharp.Core.dll diff --git a/src/CommandLine/Core/ReflectionExtensions.cs b/src/CommandLine/Core/ReflectionExtensions.cs index 068b3034..ad19e411 100644 --- a/src/CommandLine/Core/ReflectionExtensions.cs +++ b/src/CommandLine/Core/ReflectionExtensions.cs @@ -14,6 +14,8 @@ namespace CommandLine.Core { static class ReflectionExtensions { + public const string CannotSetValueToTargetInstance = "Cannot set value to target instance."; + public static IEnumerable GetSpecifications(this Type type, Func selector) { return from pi in type.FlattenHierarchy().SelectMany(x => x.GetTypeInfo().GetProperties()) @@ -98,7 +100,7 @@ public static TargetType ToTargetType(this Type type) private static T SetValue(this PropertyInfo property, T instance, object value) { Action fail = inner => { - throw new InvalidOperationException("Cannot set value to target instance.", inner); + throw new InvalidOperationException(CannotSetValueToTargetInstance, inner); }; try @@ -123,6 +125,11 @@ private static T SetValue(this PropertyInfo property, T instance, object valu { fail(e); } + catch(ArgumentException e) + { + var argEx = new ArgumentException(InvalidAttributeConfigurationError.ErrorMessage, e); + fail(argEx); + } return instance; } diff --git a/src/CommandLine/Error.cs b/src/CommandLine/Error.cs index 475ac8e3..a902609d 100644 --- a/src/CommandLine/Error.cs +++ b/src/CommandLine/Error.cs @@ -60,7 +60,11 @@ public enum ErrorType /// /// Value of type. /// - VersionRequestedError + VersionRequestedError, + /// + /// Value of type. + /// + InvalidAttributeConfigurationError } /// @@ -471,4 +475,19 @@ internal VersionRequestedError() { } } + + + /// + /// Models an error generated when an invalid token is detected. + /// + public sealed class InvalidAttributeConfigurationError : Error + { + public const string ErrorMessage = "Check if Option or Value attribute values are set properly for the given type."; + + internal InvalidAttributeConfigurationError() + : base(ErrorType.InvalidAttributeConfigurationError, true) + { + } + } + } \ No newline at end of file diff --git a/tests/CommandLine.Tests.Properties/CommandLine.Tests.Properties.csproj b/tests/CommandLine.Tests.Properties/CommandLine.Tests.Properties.csproj index cb2b6b96..1c8bc675 100644 --- a/tests/CommandLine.Tests.Properties/CommandLine.Tests.Properties.csproj +++ b/tests/CommandLine.Tests.Properties/CommandLine.Tests.Properties.csproj @@ -58,12 +58,12 @@ - + <__paket__xunit_runner_visualstudio_props>net20\xunit.runner.visualstudio - + <__paket__xunit_runner_visualstudio_props>portable-net45+win8+wp8+wpa81\xunit.runner.visualstudio @@ -94,7 +94,7 @@ <__paket__xunit_core_props>Xamarin.iOS\xunit.core - + <__paket__xunit_core_props>monoandroid\xunit.core @@ -109,7 +109,7 @@ <__paket__xunit_core_props>portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core - + <__paket__xunit_core_props>portable-win81+wpa81\xunit.core <__paket__xunit_core_targets>portable-win81+wpa81\xunit.core @@ -137,7 +137,7 @@ --> - + ..\..\packages\FluentAssertions\lib\monoandroid\FluentAssertions.Core.dll @@ -169,7 +169,7 @@ - + ..\..\packages\FluentAssertions\lib\net45\FluentAssertions.dll @@ -183,7 +183,7 @@ - + ..\..\packages\FluentAssertions\lib\portable-net40+sl5+win8+wp8+wpa81\FluentAssertions.dll @@ -197,7 +197,7 @@ - + ..\..\packages\FluentAssertions\lib\portable-win81+wpa81\FluentAssertions.dll @@ -255,7 +255,7 @@ - + ..\..\packages\FsCheck\lib\net45\FsCheck.dll @@ -264,7 +264,7 @@ - + ..\..\packages\FsCheck\lib\portable-net45+netcore45\FsCheck.dll @@ -302,7 +302,7 @@ - + ..\..\packages\FSharp.Core\lib\net40\FSharp.Core.dll @@ -311,7 +311,7 @@ - + ..\..\packages\FSharp.Core\lib\portable-net45+netcore45\FSharp.Core.dll @@ -349,7 +349,7 @@ - + ..\..\packages\xunit.abstractions\lib\net35\xunit.abstractions.dll @@ -358,7 +358,7 @@ - + ..\..\packages\xunit.abstractions\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.abstractions.dll @@ -369,7 +369,7 @@ - + ..\..\packages\xunit.assert\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll @@ -380,7 +380,7 @@ - + ..\..\packages\xunit.extensibility.core\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll diff --git a/tests/CommandLine.Tests/CommandLine.Tests.csproj b/tests/CommandLine.Tests/CommandLine.Tests.csproj index 9ecf4fcf..77287318 100644 --- a/tests/CommandLine.Tests/CommandLine.Tests.csproj +++ b/tests/CommandLine.Tests/CommandLine.Tests.csproj @@ -100,6 +100,7 @@ + @@ -142,12 +143,12 @@ - + <__paket__xunit_runner_visualstudio_props>net20\xunit.runner.visualstudio - + <__paket__xunit_runner_visualstudio_props>portable-net45+win8+wp8+wpa81\xunit.runner.visualstudio @@ -178,7 +179,7 @@ <__paket__xunit_core_props>Xamarin.iOS\xunit.core - + <__paket__xunit_core_props>monoandroid\xunit.core @@ -193,7 +194,7 @@ <__paket__xunit_core_props>portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core - + <__paket__xunit_core_props>portable-win81+wpa81\xunit.core <__paket__xunit_core_targets>portable-win81+wpa81\xunit.core @@ -219,7 +220,7 @@ --> - + ..\..\packages\FluentAssertions\lib\monoandroid\FluentAssertions.Core.dll @@ -251,7 +252,7 @@ - + ..\..\packages\FluentAssertions\lib\net45\FluentAssertions.dll @@ -265,7 +266,7 @@ - + ..\..\packages\FluentAssertions\lib\portable-net40+sl5+win8+wp8+wpa81\FluentAssertions.dll @@ -279,7 +280,7 @@ - + ..\..\packages\FluentAssertions\lib\portable-win81+wpa81\FluentAssertions.dll @@ -346,8 +347,16 @@ - - + + + + ..\..\packages\FSharp.Core\lib\net40\FSharp.Core.dll + True + True + + + + ..\..\packages\FSharp.Core\lib\portable-net45+netcore45\FSharp.Core.dll @@ -385,7 +394,7 @@ - + ..\..\packages\xunit.abstractions\lib\net35\xunit.abstractions.dll @@ -394,7 +403,7 @@ - + ..\..\packages\xunit.abstractions\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.abstractions.dll @@ -405,7 +414,7 @@ - + ..\..\packages\xunit.assert\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll @@ -416,7 +425,7 @@ - + ..\..\packages\xunit.extensibility.core\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll diff --git a/tests/CommandLine.Tests/Fakes/Options_With_InvalidDefaults.cs b/tests/CommandLine.Tests/Fakes/Options_With_InvalidDefaults.cs new file mode 100644 index 00000000..cedb1136 --- /dev/null +++ b/tests/CommandLine.Tests/Fakes/Options_With_InvalidDefaults.cs @@ -0,0 +1,11 @@ + +namespace CommandLine.Tests.Fakes +{ + class Options_With_InvalidDefaults + { + // Default of string and integer type property will also throw. + + [Option(Default = false)] + public string FileName { get; set; } + } +} diff --git a/tests/CommandLine.Tests/Unit/Core/InstanceBuilderTests.cs b/tests/CommandLine.Tests/Unit/Core/InstanceBuilderTests.cs index 7a49b39b..f6d30739 100644 --- a/tests/CommandLine.Tests/Unit/Core/InstanceBuilderTests.cs +++ b/tests/CommandLine.Tests/Unit/Core/InstanceBuilderTests.cs @@ -1039,6 +1039,21 @@ public void Parse_TimeSpan() // Teardown } + [Fact] + public void Build_DefaultBoolTypeString_ThrowsInvalidOperationException() + { + // Exercize system + Action test = () => InvokeBuild( + new string[] { }); + + // Verify outcome + test.ShouldThrow() + .WithMessage(ReflectionExtensions.CannotSetValueToTargetInstance) + .WithInnerException() + .WithInnerMessage(InvalidAttributeConfigurationError.ErrorMessage); + } + + public static IEnumerable RequiredValueStringData { get From 2da82095b5a737af03c6c60c64d21b0459a38635 Mon Sep 17 00:00:00 2001 From: "John D. Kane" Date: Sat, 1 Dec 2018 16:52:53 -0500 Subject: [PATCH 02/18] Remove duplication by delegating calls to CreateDefaultImmutableInstance(Type[]) to the overloaded function CreateDefaultImmutableInstance(Type, Type[]) which has the same code and logic. --- src/CommandLine/Infrastructure/ReflectionHelper.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/CommandLine/Infrastructure/ReflectionHelper.cs b/src/CommandLine/Infrastructure/ReflectionHelper.cs index c054f83c..c7443fec 100644 --- a/src/CommandLine/Infrastructure/ReflectionHelper.cs +++ b/src/CommandLine/Infrastructure/ReflectionHelper.cs @@ -84,11 +84,8 @@ public static bool IsFSharpOptionType(Type type) public static T CreateDefaultImmutableInstance(Type[] constructorTypes) { - var t = typeof(T); - var ctor = t.GetTypeInfo().GetConstructor(constructorTypes); - var values = (from prms in ctor.GetParameters() - select prms.ParameterType.CreateDefaultForImmutable()).ToArray(); - return (T)ctor.Invoke(values); + var t = typeof(T); + return (T)CreateDefaultImmutableInstance(t, constructorTypes); } public static object CreateDefaultImmutableInstance(Type type, Type[] constructorTypes) From 154735186ff8abd66596acbe5dde4e868e0ac1d3 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Wed, 9 Jan 2019 17:11:58 -0500 Subject: [PATCH 03/18] release version 2.4.0 --- appveyor.yml | 2 +- src/CommandLine/CommandLine.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 7069584a..1268be54 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,5 @@ #version should be only changed with RELEASE eminent, see RELEASE.md -version: 2.3.{build} +version: 2.4.0 clone_depth: 1 pull_requests: diff --git a/src/CommandLine/CommandLine.csproj b/src/CommandLine/CommandLine.csproj index ba3bc243..46cd3c1c 100644 --- a/src/CommandLine/CommandLine.csproj +++ b/src/CommandLine/CommandLine.csproj @@ -14,7 +14,7 @@ gsscoder;nemec;ericnewton76 Command Line Parser Library $(VersionSuffix) - 2.3.0 + 2.4.0 Terse syntax C# command line parser for .NET. For FSharp support see CommandLineParser.FSharp. The Command Line Parser Library offers to CLR applications a clean and concise API for manipulating command line arguments and related tasks. Terse syntax C# command line parser for .NET with F# support. The Command Line Parser Library offers to CLR applications a clean and concise API for manipulating command line arguments and related tasks. Copyright (c) 2005 - 2018 Giacomo Stelluti Scala & Contributors From ae1e6892e20b91a4d2738e0ff5e2053ef4ec3e8e Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Wed, 9 Jan 2019 17:28:59 -0500 Subject: [PATCH 04/18] fix nuget apikey --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 1268be54..ef4a5fbe 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -41,7 +41,7 @@ on_failure: deploy: - provider: NuGet api_key: - secure: +Zxb8M5W+UJV1yd9n8seu3PvH/hGNPEmgriGBnsSmtxjKPQAJ4+iL7tKAmfPHAuG + secure: Ab4T/48EyIJhVrqkfKdUxmHUtseEVuXuyrGACxZ0KN35rb/BzABlBM2YjZojicvT artifact: 'NuGetPackages' on: APPVEYOR_REPO_TAG: true From 2b592a2ef892f597d62e759ddd6520542cbf22de Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Wed, 9 Jan 2019 17:42:28 -0500 Subject: [PATCH 05/18] kick everything to get 2.4.0 out --- appveyor.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index ef4a5fbe..b5a03e54 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -45,4 +45,3 @@ deploy: artifact: 'NuGetPackages' on: APPVEYOR_REPO_TAG: true - From 9603f086a851bd33857f82f1379460a1b362ce57 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Wed, 9 Jan 2019 18:13:59 -0500 Subject: [PATCH 06/18] fix github release deployment --- appveyor.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index b5a03e54..69bfefbf 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,5 @@ #version should be only changed with RELEASE eminent, see RELEASE.md -version: 2.4.0 +version: 2.4.{build} clone_depth: 1 pull_requests: @@ -39,6 +39,14 @@ on_failure: appveyor PushArtifact .\files.lst -DeploymentName "Failed Build File Listing" deploy: +- provider: GitHub + auth_token: + secure: hVyVwHl0JiVq0VxXB4VMRWbUtrGclIzadfnWFcWCQBLvbgMLahLBnWlwGglT63pZ + artifact: NugetPackage + prerelease: false + on: + APPVEYOR_REPO_TAG: true + - provider: NuGet api_key: secure: Ab4T/48EyIJhVrqkfKdUxmHUtseEVuXuyrGACxZ0KN35rb/BzABlBM2YjZojicvT From 34b4f881eecb59c216256c676518646f29ea570a Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Wed, 9 Jan 2019 18:23:06 -0500 Subject: [PATCH 07/18] fix missing fsharp from github release deployment --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index 69bfefbf..e1935087 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -44,6 +44,7 @@ deploy: secure: hVyVwHl0JiVq0VxXB4VMRWbUtrGclIzadfnWFcWCQBLvbgMLahLBnWlwGglT63pZ artifact: NugetPackage prerelease: false + force_update: true #fsharp package runs as separate build job, so have to force_update to add fsharp.nuget added on: APPVEYOR_REPO_TAG: true From c606387088a7c38c49af896a4f0c675c13e1e0a6 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Wed, 9 Jan 2019 18:28:33 -0500 Subject: [PATCH 08/18] found mismatched case of artifacts names in deployments --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index e1935087..a3b73034 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -31,7 +31,7 @@ after_test: artifacts: - path: 'src/CommandLine/bin/Release/*.nupkg' - name: NugetPackages + name: NuGetPackages on_failure: - cmd: | @@ -42,7 +42,7 @@ deploy: - provider: GitHub auth_token: secure: hVyVwHl0JiVq0VxXB4VMRWbUtrGclIzadfnWFcWCQBLvbgMLahLBnWlwGglT63pZ - artifact: NugetPackage + artifact: 'NuGetPackages' prerelease: false force_update: true #fsharp package runs as separate build job, so have to force_update to add fsharp.nuget added on: From be60128a2128a341bad5cc4ddc3b7e7e324752d8 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Thu, 17 Jan 2019 22:12:51 -0500 Subject: [PATCH 09/18] fixed #391 --- CommandLine.sln | 9 +++++++-- src/CommandLine/CommandLine.csproj | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CommandLine.sln b/CommandLine.sln index 06356a14..102837f1 100644 --- a/CommandLine.sln +++ b/CommandLine.sln @@ -3,9 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27703.2042 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandLine", "src\CommandLine\CommandLine.csproj", "{E1BD3C65-49C3-49E7-BABA-C60980CB3F20}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommandLine", "src\CommandLine\CommandLine.csproj", "{E1BD3C65-49C3-49E7-BABA-C60980CB3F20}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandLine.Tests", "tests\CommandLine.Tests\CommandLine.Tests.csproj", "{0A15C4D2-B3E9-43AB-8155-1B39F7AC8A5E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommandLine.Tests", "tests\CommandLine.Tests\CommandLine.Tests.csproj", "{0A15C4D2-B3E9-43AB-8155-1B39F7AC8A5E}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{1361E8B1-D0E1-493E-B8C1-7380A7B7C472}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -25,6 +27,9 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {0A15C4D2-B3E9-43AB-8155-1B39F7AC8A5E} = {1361E8B1-D0E1-493E-B8C1-7380A7B7C472} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {5B5A476C-82FB-49FB-B592-5224D9005186} EndGlobalSection diff --git a/src/CommandLine/CommandLine.csproj b/src/CommandLine/CommandLine.csproj index ba3bc243..08b5b983 100644 --- a/src/CommandLine/CommandLine.csproj +++ b/src/CommandLine/CommandLine.csproj @@ -19,7 +19,7 @@ Terse syntax C# command line parser for .NET with F# support. The Command Line Parser Library offers to CLR applications a clean and concise API for manipulating command line arguments and related tasks. Copyright (c) 2005 - 2018 Giacomo Stelluti Scala & Contributors https://raw.githubusercontent.com/gsscoder/commandline/master/doc/LICENSE - https://github.com/gsscoder/commandline + https://github.com/commandlineparser/commandline https://raw.githubusercontent.com/commandlineparser/commandline/master/art/CommandLine20.png command line;commandline;argument;option;parser;parsing;library;syntax;shell From 4bd363a2a84feffe736c7a406d5d035003d47fe3 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Fri, 18 Jan 2019 00:22:44 -0500 Subject: [PATCH 10/18] added .editorconfig --- .editorconfig | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..b713459b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,26 @@ +#top-most EditorConfig for project +root = true + +[*] +end_of_line = crlf +insert_final_newline = true + +[*.cs] +indent_style = space +indent_size = 4 + +[*.{xml,csproj,config}] +indent_style = tab +indent_size = 4 + +[*.json] +indent_style = space +indent_size = 2 + +[*.js] +indent_style = space +indent_size = 2 + +[*.yml] +indent_style = space +indent_size = 2 From ebc6f3716519ebaa5337794e52ea13bfdc24b1af Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Fri, 18 Jan 2019 00:32:53 -0500 Subject: [PATCH 11/18] readability campaign: shift anon functions into actual named functions --- src/CommandLine/Core/InstanceBuilder.cs | 109 +++++++++++++------ src/CommandLine/Core/ReflectionExtensions.cs | 13 ++- 2 files changed, 80 insertions(+), 42 deletions(-) diff --git a/src/CommandLine/Core/InstanceBuilder.cs b/src/CommandLine/Core/InstanceBuilder.cs index 82c29ea8..a1fdd9f2 100644 --- a/src/CommandLine/Core/InstanceBuilder.cs +++ b/src/CommandLine/Core/InstanceBuilder.cs @@ -82,44 +82,19 @@ static class InstanceBuilder var specPropsWithValue = optionSpecPropsResult.SucceededWith().Concat(valueSpecPropsResult.SucceededWith()).Memorize(); - var setPropertyErrors = new List(); + var setPropertyErrors = new List(); - Func buildMutable = () => + //build the instance, determining if the type is mutable or not. + T instance; + if(typeInfo.IsMutable() == true) { - var mutable = factory.MapValueOrDefault(f => f(), Activator.CreateInstance()); - setPropertyErrors.AddRange(mutable.SetProperties(specPropsWithValue, sp => sp.Value.IsJust(), sp => sp.Value.FromJustOrFail())); - setPropertyErrors.AddRange(mutable.SetProperties( - specPropsWithValue, - sp => sp.Value.IsNothing() && sp.Specification.DefaultValue.IsJust(), - sp => sp.Specification.DefaultValue.FromJustOrFail())); - setPropertyErrors.AddRange(mutable.SetProperties( - specPropsWithValue, - sp => - sp.Value.IsNothing() && sp.Specification.TargetType == TargetType.Sequence - && sp.Specification.DefaultValue.MatchNothing(), - sp => sp.Property.PropertyType.GetTypeInfo().GetGenericArguments().Single().CreateEmptyArray())); - return mutable; - }; - - Func buildImmutable = () => + instance = BuildMutable(factory, specPropsWithValue, setPropertyErrors); + } + else { - var ctor = typeInfo.GetTypeInfo().GetConstructor((from sp in specProps select sp.Property.PropertyType).ToArray()); - var values = (from prms in ctor.GetParameters() - join sp in specPropsWithValue on prms.Name.ToLower() equals sp.Property.Name.ToLower() into spv - from sp in spv.DefaultIfEmpty() - select - sp == null - ? specProps.First(s => String.Equals(s.Property.Name, prms.Name, StringComparison.CurrentCultureIgnoreCase)) - .Property.PropertyType.GetDefaultValue() - : sp.Value.GetValueOrDefault( - sp.Specification.DefaultValue.GetValueOrDefault( - sp.Specification.ConversionType.CreateDefaultForImmutable()))).ToArray(); - var immutable = (T)ctor.Invoke(values); - return immutable; - }; - - var instance = typeInfo.IsMutable() ? buildMutable() : buildImmutable(); - + instance = BuildImmutable(typeInfo, factory, specProps, specPropsWithValue, setPropertyErrors); + } + var validationErrors = specPropsWithValue.Validate(SpecificationPropertyRules.Lookup(tokens)); var allErrors = @@ -150,5 +125,67 @@ static class InstanceBuilder return result; } + + private static T BuildMutable(Maybe> factory, IEnumerable specPropsWithValue, List setPropertyErrors ) + { + var mutable = factory.MapValueOrDefault(f => f(), Activator.CreateInstance()); + + setPropertyErrors.AddRange( + mutable.SetProperties( + specPropsWithValue, + sp => sp.Value.IsJust(), + sp => sp.Value.FromJustOrFail() + ) + ); + + setPropertyErrors.AddRange( + mutable.SetProperties( + specPropsWithValue, + sp => sp.Value.IsNothing() && sp.Specification.DefaultValue.IsJust(), + sp => sp.Specification.DefaultValue.FromJustOrFail() + ) + ); + + setPropertyErrors.AddRange( + mutable.SetProperties( + specPropsWithValue, + sp => sp.Value.IsNothing() + && sp.Specification.TargetType == TargetType.Sequence + && sp.Specification.DefaultValue.MatchNothing(), + sp => sp.Property.PropertyType.GetTypeInfo().GetGenericArguments().Single().CreateEmptyArray() + ) + ); + + return mutable; + } + + private static T BuildImmutable(Type typeInfo, Maybe> factory, IEnumerable specProps, IEnumerable specPropsWithValue, List setPropertyErrors) + { + var ctor = typeInfo.GetTypeInfo().GetConstructor( + specProps.Select(sp => sp.Property.PropertyType).ToArray() + ); + + if(ctor == null) + { + throw new InvalidOperationException($"Type appears to be immutable, but no constructor found for type {typeInfo.FullName} to accept values."); + } + + var values = + (from prms in ctor.GetParameters() + join sp in specPropsWithValue on prms.Name.ToLower() equals sp.Property.Name.ToLower() into spv + from sp in spv.DefaultIfEmpty() + select + sp == null + ? specProps.First(s => String.Equals(s.Property.Name, prms.Name, StringComparison.CurrentCultureIgnoreCase)) + .Property.PropertyType.GetDefaultValue() + : sp.Value.GetValueOrDefault( + sp.Specification.DefaultValue.GetValueOrDefault( + sp.Specification.ConversionType.CreateDefaultForImmutable()))).ToArray(); + + var immutable = (T)ctor.Invoke(values); + + return immutable; + } + } -} \ No newline at end of file +} diff --git a/src/CommandLine/Core/ReflectionExtensions.cs b/src/CommandLine/Core/ReflectionExtensions.cs index c82ebefc..cd75e07e 100644 --- a/src/CommandLine/Core/ReflectionExtensions.cs +++ b/src/CommandLine/Core/ReflectionExtensions.cs @@ -122,12 +122,13 @@ public static object GetDefaultValue(this Type type) public static bool IsMutable(this Type type) { - Func isMutable = () => { - var props = type.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance).Any(p => p.CanWrite); - var fields = type.GetTypeInfo().GetFields(BindingFlags.Public | BindingFlags.Instance).Any(); - return props || fields; - }; - return type != typeof(object) ? isMutable() : true; + if(type == typeof(object)) + return true; + + var props = type.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance).Any(p => p.CanWrite); + var fields = type.GetTypeInfo().GetFields(BindingFlags.Public | BindingFlags.Instance).Any(); + + return props || fields; } public static object CreateDefaultForImmutable(this Type type) From d9efdac38848e007e93da76305b322d03875193e Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Fri, 18 Jan 2019 00:34:03 -0500 Subject: [PATCH 12/18] added test for invalid situation where options class has properties with no setter and no valid constructor --- .../Unit/Core/InstanceBuilderTests.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/CommandLine.Tests/Unit/Core/InstanceBuilderTests.cs b/tests/CommandLine.Tests/Unit/Core/InstanceBuilderTests.cs index fe2d9ec6..c150d23a 100644 --- a/tests/CommandLine.Tests/Unit/Core/InstanceBuilderTests.cs +++ b/tests/CommandLine.Tests/Unit/Core/InstanceBuilderTests.cs @@ -1133,6 +1133,21 @@ public void Parse_TimeSpan() // Teardown } + [Fact] + public void OptionClass_IsImmutable_HasNoCtor() + { + Action act = () => InvokeBuild(new string[] { "Test" }, false, false); + + act.Should().Throw(); + } + + private class ValueWithNoSetterOptions + { + [Value(0, MetaName = "Test", Default = 0)] + public int TestValue { get; } + } + + public static IEnumerable RequiredValueStringData { get From 5f4c11d4ceea14040950b8edb0ae408d915f9d3e Mon Sep 17 00:00:00 2001 From: Sascha Falk Date: Fri, 25 Jan 2019 07:16:48 +0100 Subject: [PATCH 13/18] Added explicit support for .NET 4.6.1 and .NET Core 2.0. Eliminates the need for interfacing libraries reducing the footprint of an application built with the CommandLine library. --- src/CommandLine/CommandLine.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CommandLine/CommandLine.csproj b/src/CommandLine/CommandLine.csproj index 46cd3c1c..cd16cc54 100644 --- a/src/CommandLine/CommandLine.csproj +++ b/src/CommandLine/CommandLine.csproj @@ -3,7 +3,7 @@ CommandLine Library - netstandard2.0 + netstandard2.0; net461; netcoreapp2.0 $(DefineConstants);CSX_EITHER_INTERNAL;CSX_REM_EITHER_BEYOND_2;CSX_ENUM_INTERNAL;ERRH_INTERNAL;ERRH_DISABLE_INLINE_METHODS;CSX_MAYBE_INTERNAL;CSX_REM_EITHER_FUNC $(DefineConstants);SKIP_FSHARP true From cdfe65538cb70ac215ddc917a84d0c28375e68cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Luthi?= Date: Fri, 25 Jan 2019 12:51:05 +0100 Subject: [PATCH 14/18] Reset attribute overrides when the test is disposed This unclutters all tests that need to reset the attribute overrides --- .../Unit/Text/HelpTextTests.cs | 121 ++++++++---------- 1 file changed, 51 insertions(+), 70 deletions(-) diff --git a/tests/CommandLine.Tests/Unit/Text/HelpTextTests.cs b/tests/CommandLine.Tests/Unit/Text/HelpTextTests.cs index 0c6e5022..6ef21ac0 100644 --- a/tests/CommandLine.Tests/Unit/Text/HelpTextTests.cs +++ b/tests/CommandLine.Tests/Unit/Text/HelpTextTests.cs @@ -2,13 +2,10 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using System.Reflection; -using CommandLine.Core; using CommandLine.Infrastructure; using CommandLine.Tests.Fakes; -using CommandLine.Tests.Unit.Infrastructure; using CommandLine.Text; using FluentAssertions; using Xunit; @@ -16,8 +13,13 @@ namespace CommandLine.Tests.Unit.Text { - public class HelpTextTests + public class HelpTextTests : IDisposable { + public void Dispose() + { + ReflectionHelper.SetAttributeOverride(null); + } + [Fact] public void Create_empty_instance() { @@ -573,91 +575,70 @@ public void Default_set_to_sequence_should_be_properly_printed() [Fact] public void AutoBuild_when_no_assembly_attributes() { - try - { - string expectedCopyright = "Copyright (C) 1 author"; + string expectedCopyright = "Copyright (C) 1 author"; - ReflectionHelper.SetAttributeOverride(new Attribute[0]); + ReflectionHelper.SetAttributeOverride(new Attribute[0]); - ParserResult fakeResult = new NotParsed( - TypeInfo.Create(typeof (Simple_Options)), new Error[0]); - bool onErrorCalled = false; - HelpText actualResult = HelpText.AutoBuild(fakeResult, ht => - { - onErrorCalled = true; - return ht; - }, ex => ex); - - onErrorCalled.Should().BeTrue(); - actualResult.Copyright.Should().Be(expectedCopyright); - } - finally + ParserResult fakeResult = new NotParsed( + TypeInfo.Create(typeof (Simple_Options)), new Error[0]); + bool onErrorCalled = false; + HelpText actualResult = HelpText.AutoBuild(fakeResult, ht => { - ReflectionHelper.SetAttributeOverride(null); - } + onErrorCalled = true; + return ht; + }, ex => ex); + + onErrorCalled.Should().BeTrue(); + actualResult.Copyright.Should().Be(expectedCopyright); } [Fact] public void AutoBuild_with_assembly_title_and_version_attributes_only() { - try - { - string expectedTitle = "Title"; - string expectedVersion = "1.2.3.4"; + string expectedTitle = "Title"; + string expectedVersion = "1.2.3.4"; - ReflectionHelper.SetAttributeOverride(new Attribute[] - { - new AssemblyTitleAttribute(expectedTitle), - new AssemblyInformationalVersionAttribute(expectedVersion) - }); - - ParserResult fakeResult = new NotParsed( - TypeInfo.Create(typeof (Simple_Options)), new Error[0]); - bool onErrorCalled = false; - HelpText actualResult = HelpText.AutoBuild(fakeResult, ht => - { - onErrorCalled = true; - return ht; - }, ex => ex); - - onErrorCalled.Should().BeTrue(); - actualResult.Heading.Should().Be(string.Format("{0} {1}", expectedTitle, expectedVersion)); - } - finally + ReflectionHelper.SetAttributeOverride(new Attribute[] + { + new AssemblyTitleAttribute(expectedTitle), + new AssemblyInformationalVersionAttribute(expectedVersion) + }); + + ParserResult fakeResult = new NotParsed( + TypeInfo.Create(typeof (Simple_Options)), new Error[0]); + bool onErrorCalled = false; + HelpText actualResult = HelpText.AutoBuild(fakeResult, ht => { - ReflectionHelper.SetAttributeOverride(null); - } + onErrorCalled = true; + return ht; + }, ex => ex); + + onErrorCalled.Should().BeTrue(); + actualResult.Heading.Should().Be(string.Format("{0} {1}", expectedTitle, expectedVersion)); } [Fact] public void AutoBuild_with_assembly_company_attribute_only() { - try - { - string expectedCompany = "Company"; + string expectedCompany = "Company"; - ReflectionHelper.SetAttributeOverride(new Attribute[] - { - new AssemblyCompanyAttribute(expectedCompany) - }); + ReflectionHelper.SetAttributeOverride(new Attribute[] + { + new AssemblyCompanyAttribute(expectedCompany) + }); - ParserResult fakeResult = new NotParsed( - TypeInfo.Create(typeof (Simple_Options)), new Error[0]); - bool onErrorCalled = false; - HelpText actualResult = HelpText.AutoBuild(fakeResult, ht => - { - onErrorCalled = true; - return ht; - }, ex => ex); - - onErrorCalled.Should().BeFalse(); // Other attributes have fallback logic - actualResult.Copyright.Should().Be(string.Format("Copyright (C) {0} {1}", DateTime.Now.Year, expectedCompany)); - } - finally + ParserResult fakeResult = new NotParsed( + TypeInfo.Create(typeof (Simple_Options)), new Error[0]); + bool onErrorCalled = false; + HelpText actualResult = HelpText.AutoBuild(fakeResult, ht => { - ReflectionHelper.SetAttributeOverride(null); - } + onErrorCalled = true; + return ht; + }, ex => ex); + + onErrorCalled.Should().BeFalse(); // Other attributes have fallback logic + actualResult.Copyright.Should().Be(string.Format("Copyright (C) {0} {1}", DateTime.Now.Year, expectedCompany)); } [Fact] From 678528659cb2f33137b9b7c1c0457024d8d22341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BCller?= Date: Sat, 26 Jan 2019 12:26:22 +0100 Subject: [PATCH 15/18] Adjusts link to 'verb commands' --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f11109e..91727097 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ __This library provides _hassle free_ command line parsing with a constantly upd - Supports `--help`, `--version`, `version` and `help [verb]` by default. - Map to sequences (via `IEnumerable` and similar) and scalar types, including Enums and `Nullable`. - You can also map to every type with a constructor that accepts a string (like `System.Uri`). -- Define [verb commands](https://github.com/commandlineparser/commandline/wiki#verbs) similar to `git commit -a`. +- Define [verb commands](https://github.com/commandlineparser/commandline/wiki/Verbs) similar to `git commit -a`. - Unparsing support: `CommandLine.Parser.Default.FormatCommandLine(T options)`. - CommandLineParser.FSharp package is F#-friendly with support for `option<'a>`, see [demo](https://github.com/commandlineparser/commandline/blob/master/demo/fsharp-demo.fsx). _NOTE: This is a separate NuGet package._ - Most of features applies with a [CoC](http://en.wikipedia.org/wiki/Convention_over_configuration) philosophy. From 0dac5acb2644db7e444e67e82d4ebacfc570192f Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Fri, 1 Feb 2019 12:46:36 -0500 Subject: [PATCH 16/18] add specific image to make sure Visual Studio 2017 environment used --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index a3b73034..c7979afb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,8 @@ #version should be only changed with RELEASE eminent, see RELEASE.md version: 2.4.{build} +image: Visual Studio 2017 + clone_depth: 1 pull_requests: do_not_increment_build_number: true From 6d2dc12f0c31600ba7c00a7385982d9487b63f79 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Fri, 1 Feb 2019 12:54:02 -0500 Subject: [PATCH 17/18] fixed bad merge of Error.cs in build --- src/CommandLine/Error.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CommandLine/Error.cs b/src/CommandLine/Error.cs index b1bc3e94..90ee26d8 100644 --- a/src/CommandLine/Error.cs +++ b/src/CommandLine/Error.cs @@ -64,7 +64,8 @@ public enum ErrorType /// /// Value of type. /// - SetValueExceptionError + SetValueExceptionError, + VersionRequestedError, /// /// Value of type. From 030eb8d431c0c56b62277c654d0951308e873960 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Fri, 1 Feb 2019 13:01:01 -0500 Subject: [PATCH 18/18] @moh-hassan helped fix FSharp side of build --- src/CommandLine/CommandLine.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CommandLine/CommandLine.csproj b/src/CommandLine/CommandLine.csproj index 46e6d82d..3764bcb6 100644 --- a/src/CommandLine/CommandLine.csproj +++ b/src/CommandLine/CommandLine.csproj @@ -14,7 +14,7 @@ gsscoder;nemec;ericnewton76 Command Line Parser Library $(VersionSuffix) - 2.4.0 + 0.0.0 Terse syntax C# command line parser for .NET. For FSharp support see CommandLineParser.FSharp. The Command Line Parser Library offers to CLR applications a clean and concise API for manipulating command line arguments and related tasks. Terse syntax C# command line parser for .NET with F# support. The Command Line Parser Library offers to CLR applications a clean and concise API for manipulating command line arguments and related tasks. Copyright (c) 2005 - 2018 Giacomo Stelluti Scala & Contributors @@ -35,7 +35,7 @@ - +