diff --git a/CommandLine.snk b/CommandLine.snk index 96087a73..6b0b6501 100644 Binary files a/CommandLine.snk and b/CommandLine.snk differ diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 00000000..a6a8d8db --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,8 @@ + + + CS1591;CS0219;8002;NU5125 + + + $(DefineConstants);NETFRAMEWORK + + \ No newline at end of file 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 3764bcb6..6601024a 100644 --- a/src/CommandLine/CommandLine.csproj +++ b/src/CommandLine/CommandLine.csproj @@ -3,7 +3,7 @@ CommandLine Library - netstandard2.0; net461; netcoreapp2.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 @@ -22,6 +22,8 @@ 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 + true + 7.3 diff --git a/src/CommandLine/Infrastructure/ReflectionHelper.cs b/src/CommandLine/Infrastructure/ReflectionHelper.cs index 82acb674..e2177947 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]) @@ -93,7 +98,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/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/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")] diff --git a/tests/CommandLine.Tests/CommandLine.Tests.csproj b/tests/CommandLine.Tests/CommandLine.Tests.csproj index 0c28967a..99832d50 100644 --- a/tests/CommandLine.Tests/CommandLine.Tests.csproj +++ b/tests/CommandLine.Tests/CommandLine.Tests.csproj @@ -2,18 +2,24 @@ Library - netcoreapp2.0 - $(DefineConstants);PLATFORM_DOTNET + net461;netcoreapp2.0 $(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 + true - - + + $(DefineConstants);PLATFORM_DOTNET + @@ -22,8 +28,11 @@ - - + + + + + \ 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 + }), + }; + } + + } + } +} 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