From a0c130ef31399bf6002f31ecc5ba3c7bc03fdd77 Mon Sep 17 00:00:00 2001 From: "Moh.Hassan" Date: Thu, 10 Jan 2019 05:11:27 +0200 Subject: [PATCH 1/5] add support for net40 and net45 --- demo/ReadText.Demo/ReadText.Demo.csproj | 50 ++----------------- demo/ReadText.Demo/ReadText.Demo.sln | 15 ++++-- src/CommandLine/CommandLine.csproj | 5 +- .../Infrastructure/ReflectionHelper.cs | 5 ++ src/CommandLine/IntrospectionExtensions.cs | 20 ++++++++ .../CommandLine.Tests.csproj | 7 +++ 6 files changed, 51 insertions(+), 51 deletions(-) create mode 100644 src/CommandLine/IntrospectionExtensions.cs diff --git a/demo/ReadText.Demo/ReadText.Demo.csproj b/demo/ReadText.Demo/ReadText.Demo.csproj index f07c8801..71f16965 100644 --- a/demo/ReadText.Demo/ReadText.Demo.csproj +++ b/demo/ReadText.Demo/ReadText.Demo.csproj @@ -1,52 +1,10 @@ - - + - Debug - AnyCPU - 12.0.0 - 2.0 - {F9D3B288-1A73-4C91-8ED7-11ED1704B817} Exe - ReadText.Demo - ReadText.Demo + net40;net45;net461;netcoreapp2.1;netcoreapp2.0 +false - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - true - - - full - true - bin\Release - prompt - 4 - true - - - - packages\CommandLineParser.2.1.1-beta\lib\net40\CommandLine.dll - - - - - - - Properties\SharedAssemblyInfo.cs - - - - - - - Designer - + - \ No newline at end of file diff --git a/demo/ReadText.Demo/ReadText.Demo.sln b/demo/ReadText.Demo/ReadText.Demo.sln index 1cac367d..cafe0089 100644 --- a/demo/ReadText.Demo/ReadText.Demo.sln +++ b/demo/ReadText.Demo/ReadText.Demo.sln @@ -1,9 +1,11 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.106 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReadText.Demo", "ReadText.Demo.csproj", "{F9D3B288-1A73-4C91-8ED7-11ED1704B817}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReadText.Demo", "ReadText.Demo.csproj", "{F9D3B288-1A73-4C91-8ED7-11ED1704B817}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommandLine", "..\..\src\CommandLine\CommandLine.csproj", "{A03AADAC-F7E5-44A6-8BCC-492B1697CCC9}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,8 +17,15 @@ Global {F9D3B288-1A73-4C91-8ED7-11ED1704B817}.Debug|Any CPU.Build.0 = Debug|Any CPU {F9D3B288-1A73-4C91-8ED7-11ED1704B817}.Release|Any CPU.ActiveCfg = Release|Any CPU {F9D3B288-1A73-4C91-8ED7-11ED1704B817}.Release|Any CPU.Build.0 = Release|Any CPU + {A03AADAC-F7E5-44A6-8BCC-492B1697CCC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A03AADAC-F7E5-44A6-8BCC-492B1697CCC9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A03AADAC-F7E5-44A6-8BCC-492B1697CCC9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A03AADAC-F7E5-44A6-8BCC-492B1697CCC9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FF14CDF0-EF51-448B-918C-47CD369568DF} + EndGlobalSection EndGlobal diff --git a/src/CommandLine/CommandLine.csproj b/src/CommandLine/CommandLine.csproj index ba3bc243..019b44a3 100644 --- a/src/CommandLine/CommandLine.csproj +++ b/src/CommandLine/CommandLine.csproj @@ -3,7 +3,7 @@ CommandLine Library - netstandard2.0 + netstandard2.0;net40;net45;net461 $(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 @@ -14,7 +14,7 @@ gsscoder;nemec;ericnewton76 Command Line Parser Library $(VersionSuffix) - 2.3.0 + 2.5.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 @@ -22,6 +22,7 @@ https://github.com/gsscoder/commandline https://raw.githubusercontent.com/commandlineparser/commandline/master/art/CommandLine20.png command line;commandline;argument;option;parser;parsing;library;syntax;shell + true diff --git a/src/CommandLine/Infrastructure/ReflectionHelper.cs b/src/CommandLine/Infrastructure/ReflectionHelper.cs index 52bf8991..a8284180 100644 --- a/src/CommandLine/Infrastructure/ReflectionHelper.cs +++ b/src/CommandLine/Infrastructure/ReflectionHelper.cs @@ -52,7 +52,12 @@ public static Maybe GetAttribute() } var assembly = GetExecutingOrEntryAssembly(); + +#if NET40 + var attributes = assembly.GetCustomAttributes(typeof(TAttribute), false); +#else var attributes = assembly.GetCustomAttributes().ToArray(); +#endif return attributes.Length > 0 ? Maybe.Just((TAttribute)attributes[0]) diff --git a/src/CommandLine/IntrospectionExtensions.cs b/src/CommandLine/IntrospectionExtensions.cs new file mode 100644 index 00000000..8e4c64ea --- /dev/null +++ b/src/CommandLine/IntrospectionExtensions.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CommandLine +{ +#if NET40 + + internal static class IntrospectionExtensions + { + public static Type GetTypeInfo(this Type type) + { + return type; + } + } +#endif +} + diff --git a/tests/CommandLine.Tests/CommandLine.Tests.csproj b/tests/CommandLine.Tests/CommandLine.Tests.csproj index 0c28967a..274a3e38 100644 --- a/tests/CommandLine.Tests/CommandLine.Tests.csproj +++ b/tests/CommandLine.Tests/CommandLine.Tests.csproj @@ -7,6 +7,11 @@ $(DefineConstants);SKIP_FSHARP ..\..\CommandLine.snk true + gsscoder;nemec;ericnewton76 + Command Line Parser Library + $(VersionSuffix) + 2.5.0 + Copyright (c) 2005 - 2018 Giacomo Stelluti Scala & Contributors @@ -24,6 +29,8 @@ + + \ No newline at end of file From 371b61a267418fb6a94c924100ac007c6ebf5fe9 Mon Sep 17 00:00:00 2001 From: "Moh.Hassan" Date: Fri, 1 Feb 2019 20:46:07 +0200 Subject: [PATCH 2/5] fix Fsharp in net40 --- src/CommandLine/CommandLine.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CommandLine/CommandLine.csproj b/src/CommandLine/CommandLine.csproj index 019b44a3..94c76586 100644 --- a/src/CommandLine/CommandLine.csproj +++ b/src/CommandLine/CommandLine.csproj @@ -3,7 +3,7 @@ CommandLine Library - netstandard2.0;net40;net45;net461 + netstandard2.0;net40;net45;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 @@ -14,7 +14,7 @@ gsscoder;nemec;ericnewton76 Command Line Parser Library $(VersionSuffix) - 2.5.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 @@ -36,7 +36,7 @@ - + From 6a01d6c7b74b6a50aa5c9a5f5cea574c867ba795 Mon Sep 17 00:00:00 2001 From: "Moh.Hassan" Date: Tue, 9 Apr 2019 21:28:32 +0200 Subject: [PATCH 3/5] Resolve the null EntryAssembly Issues #389 #424 --- Directory.Build.props | 8 ++ src/CommandLine/CommandLine.csproj | 3 +- .../Infrastructure/ReflectionHelper.cs | 4 +- .../CommandLine.Tests.csproj | 8 +- tests/CommandLine.Tests/Unit/Issue389Tests.cs | 78 +++++++++++++++++++ 5 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 Directory.Build.props create mode 100644 tests/CommandLine.Tests/Unit/Issue389Tests.cs diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 00000000..c074efed --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,8 @@ + + + CS1591;8002;NU5125 + + + $(DefineConstants);NETFRAMEWORK + + \ No newline at end of file diff --git a/src/CommandLine/CommandLine.csproj b/src/CommandLine/CommandLine.csproj index 94c76586..5b0ea0e0 100644 --- a/src/CommandLine/CommandLine.csproj +++ b/src/CommandLine/CommandLine.csproj @@ -3,7 +3,7 @@ CommandLine Library - netstandard2.0;net40;net45;net461;netcoreapp2.0 + netstandard2.0;net40;net45 $(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 @@ -23,6 +23,7 @@ https://raw.githubusercontent.com/commandlineparser/commandline/master/art/CommandLine20.png command line;commandline;argument;option;parser;parsing;library;syntax;shell true + 7.3 diff --git a/src/CommandLine/Infrastructure/ReflectionHelper.cs b/src/CommandLine/Infrastructure/ReflectionHelper.cs index a8284180..50bea517 100644 --- a/src/CommandLine/Infrastructure/ReflectionHelper.cs +++ b/src/CommandLine/Infrastructure/ReflectionHelper.cs @@ -101,7 +101,9 @@ public static object CreateDefaultImmutableInstance(Type type, Type[] constructo private static Assembly GetExecutingOrEntryAssembly() { - return Assembly.GetEntryAssembly(); + //resolve issues of null EntryAssembly in Xunit Test #392,424,389 + //return Assembly.GetEntryAssembly(); + return Assembly.GetEntryAssembly()??Assembly.GetCallingAssembly(); } } } \ No newline at end of file diff --git a/tests/CommandLine.Tests/CommandLine.Tests.csproj b/tests/CommandLine.Tests/CommandLine.Tests.csproj index 274a3e38..6d1851a9 100644 --- a/tests/CommandLine.Tests/CommandLine.Tests.csproj +++ b/tests/CommandLine.Tests/CommandLine.Tests.csproj @@ -2,7 +2,7 @@ Library - netcoreapp2.0 + net461;netcoreapp2.0 $(DefineConstants);PLATFORM_DOTNET $(DefineConstants);SKIP_FSHARP ..\..\CommandLine.snk @@ -13,7 +13,6 @@ 2.5.0 Copyright (c) 2005 - 2018 Giacomo Stelluti Scala & Contributors - @@ -29,8 +28,9 @@ - + + - + \ No newline at end of file diff --git a/tests/CommandLine.Tests/Unit/Issue389Tests.cs b/tests/CommandLine.Tests/Unit/Issue389Tests.cs new file mode 100644 index 00000000..ef4f6169 --- /dev/null +++ b/tests/CommandLine.Tests/Unit/Issue389Tests.cs @@ -0,0 +1,78 @@ +using CommandLine.Text; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Xunit; + +namespace CommandLine.Tests.Unit +{ + //Reference: PR# 392 + public class Issue389Tests + { + + private const int ERROR_SUCCESS = 0; + + // Test method (xUnit) which fails + [Fact] + public void CallMain_GiveHelpArgument_ExpectSuccess() + { + var result = Program.__Main(new[] { "--help" }); + + Assert.Equal(ERROR_SUCCESS, result); + } + + // main program + internal class Program + { + + + internal static int __Main(string[] args) + { + bool hasError = false; + bool helpOrVersionRequested = false; + + ParserResult parsedOptions = Parser.Default.ParseArguments(args) + .WithNotParsed(errors => { + helpOrVersionRequested = errors.Any( + x => x.Tag == ErrorType.HelpRequestedError + || x.Tag == ErrorType.VersionRequestedError); + hasError = true; + }); + + if(helpOrVersionRequested) + { + return ERROR_SUCCESS; + } + + // Execute as a normal call + // ... + return ERROR_SUCCESS; + } + + } + + // Options + internal class Options + { + + [Option('c', "connectionString", Required = true, HelpText = "Texts.ExplainConnection")] + public string ConnectionString { get; set; } + + [Option('j', "jobId", Required = true, HelpText = "Texts.ExplainJob")] + public int JobId { get; set; } + + [Usage(ApplicationAlias = "Importer.exe")] + public static IEnumerable Examples + { + get => new[] { + new Example("Texts.ExplainExampleExecution", new Options() { + ConnectionString="Server=MyServer;Database=MyDatabase", + JobId = 5 + }), + }; + } + + } + } +} From 93c90070e50f2c12eab60cebaf8fb6f490bd797c Mon Sep 17 00:00:00 2001 From: "Moh.Hassan" Date: Thu, 11 Apr 2019 18:37:42 +0200 Subject: [PATCH 4/5] add testcase of issue# 424 --- Directory.Build.props | 2 +- src/CommandLine/CommandLine.csproj | 2 +- .../CommandLine.Tests.csproj | 10 ++-- tests/CommandLine.Tests/Unit/Issue424Tests.cs | 55 +++++++++++++++++++ 4 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 tests/CommandLine.Tests/Unit/Issue424Tests.cs diff --git a/Directory.Build.props b/Directory.Build.props index c074efed..a6a8d8db 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - CS1591;8002;NU5125 + CS1591;CS0219;8002;NU5125 $(DefineConstants);NETFRAMEWORK diff --git a/src/CommandLine/CommandLine.csproj b/src/CommandLine/CommandLine.csproj index 5b0ea0e0..cd666847 100644 --- a/src/CommandLine/CommandLine.csproj +++ b/src/CommandLine/CommandLine.csproj @@ -14,7 +14,7 @@ gsscoder;nemec;ericnewton76 Command Line Parser Library $(VersionSuffix) - 0.0.0 + 2.5.0-Dev 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 diff --git a/tests/CommandLine.Tests/CommandLine.Tests.csproj b/tests/CommandLine.Tests/CommandLine.Tests.csproj index 6d1851a9..99832d50 100644 --- a/tests/CommandLine.Tests/CommandLine.Tests.csproj +++ b/tests/CommandLine.Tests/CommandLine.Tests.csproj @@ -3,7 +3,6 @@ Library net461;netcoreapp2.0 - $(DefineConstants);PLATFORM_DOTNET $(DefineConstants);SKIP_FSHARP ..\..\CommandLine.snk true @@ -12,12 +11,15 @@ $(VersionSuffix) 2.5.0 Copyright (c) 2005 - 2018 Giacomo Stelluti Scala & Contributors + true - + + $(DefineConstants);PLATFORM_DOTNET + @@ -26,8 +28,8 @@ - - + + diff --git a/tests/CommandLine.Tests/Unit/Issue424Tests.cs b/tests/CommandLine.Tests/Unit/Issue424Tests.cs new file mode 100644 index 00000000..c828c3ed --- /dev/null +++ b/tests/CommandLine.Tests/Unit/Issue424Tests.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using Xunit; + +namespace CommandLine.Tests.Unit +{ + + //MailAndSmsWarningSenderTests + public class Issue424Tests + { + private MailAndSmsWarningSender _sut; + + public Issue424Tests() + { + _sut = new MailAndSmsWarningSender(); + } + + [Fact] + public void SendSmsOnWarning() + { + //Arrange + void Action() => _sut.ParseArgumentsAndRun( + new[] { "--task", "MailAndSmsWarningSender", "--test", "hejtest" }); + // Act & Assert + Assert.Throws((Action)Action); + } + } + + public class MailAndSmsWarningSender + { + internal class Options + { + [Option("task")] + public string Task { get; set; } + } + + public void ParseArgumentsAndRun(string[] args) + { + Parser.Default.ParseArguments(args) + .WithParsed(ExecuteTaskWithOptions) + .WithNotParsed(HandleParseError); + } + + private void HandleParseError(IEnumerable errs) + { + throw new NotImplementedException(); + } + + private void ExecuteTaskWithOptions(Options opts) + { + Console.WriteLine("Executing"); + } + + } +} \ No newline at end of file From 4295f74dd387f0dd173e4e2cad62b2df3d0aa157 Mon Sep 17 00:00:00 2001 From: "Moh.Hassan" Date: Sat, 27 Apr 2019 01:32:16 +0200 Subject: [PATCH 5/5] resolve appveyor build error --- CommandLine.snk | Bin 595 -> 596 bytes src/CommandLine/CommandLine.csproj | 2 +- src/CommandLine/Properties/AssemblyInfo.cs | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CommandLine.snk b/CommandLine.snk index 96087a731df6b418f70cfe6df405afeb53af9025..6b0b650111ad1ef405aa994d57732ff390e61643 100644 GIT binary patch delta 587 zcmV-R0<`_p1k?nO6n_b;B=3lv(rff@ey-Xm;QCwy#SD|i;UP176-&wrAJvM+%Z3?S zaGW6^^n!B??F69VXQg$HR?|jH`nvuCD=|?FIi?wC{pXcP4b~58IbapV_L`I+bfffT zOKsL|3}ax6>Uh2RYc;X7i?>%n!pf~5a95uwZymfWRs|8pNPp7%=L0Lq+9^7rEYzH1 zb@{H&4fIh%1A#Be9PBmhieJHVSOpkXK{`l6Zkiqvf zUcRWtL48wl7#Xzb_yk#A6%05p-l_%I6f)mJ1n0J6kLcmEP&8%^B zfHQZ&FhufHlor{V_H_)BX!P!}h6{*et5iy&Xr@NSzz+GKvhPVu0vD2Ya^gx`v<6kYi+V$6dn=DR; z3xyNavf()^Du2$m5!)`rG9pe90Qr(rr`&n6Hg7mO{we0^4%`~!U@yK2eSDpk_-g}d zug^~rk5qh2!QC@_&G;YFDY*E$El3}nIWf4gGLr+t%X1n9fovdLPQ^+})N#3*cyRmr zyuWpl43ire`CXHd2*=^2iP(&JCOBMEBmKCT-q@SNpMR$_HvZf*?{z*zU_|RnE=c)7 z^V$RgVKR}ENDOzv39QEk^RC$p!FH1XR(Z&`kQ4TD$zc`WS@J%T$3?$HvCG>S27yE; zSVgj8M^qyZKp0P%+@LP&0%1ZGa CommandLine Library - netstandard2.0;net40;net45 + netstandard2.0;net40;net45;net461 $(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 diff --git a/src/CommandLine/Properties/AssemblyInfo.cs b/src/CommandLine/Properties/AssemblyInfo.cs index 4b4532b3..1dc94d20 100644 --- a/src/CommandLine/Properties/AssemblyInfo.cs +++ b/src/CommandLine/Properties/AssemblyInfo.cs @@ -2,4 +2,4 @@ using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("CommandLine.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010015eb7571d696c075627830f9468969103bc35764467bdbccfc0850f2fbe6913ee233d5d7cf3bbcb870fd42e6a8cc846d706b5cef35389e5b90051991ee8b6ed73ee1e19f108e409be69af6219b2e31862405f4b8ba101662fbbb54ba92a35d97664fe65c90c2bebd07aef530b01b709be5ed01b7e4d67a6b01c8643e42a20fb4")] +[assembly: InternalsVisibleTo("CommandLine.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010009ab24ef889cd26bf46f7eaeda28e0fa5c04c50c93c6e121337b154bca0a1fd58ac6cb86195b709c2120f482730ced04a0e167a5758e56d3464bfabafe022b31510c39a61968fde795480dd60f6a396015c5f69a942074a3f4654b6dd66d0c63608bea78bdf96b35b1b48bb75741c2caad1f70579f286f1dbc2c560511c648d2")]