File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Text ;
4+ using MatthiWare . CommandLine ;
5+ using Xunit ;
6+
7+ namespace MatthiWare . CommandLineParser . Tests
8+ {
9+ public class CustomerReportedTests
10+ {
11+ /// <summary>
12+ /// Running with *no* parameters at all crashes the command line parser #12
13+ /// https://github.com/MatthiWare/CommandLineParser.Core/issues/12
14+ /// </summary>
15+ [ Theory ]
16+ [ InlineData ( true , true ) ]
17+ [ InlineData ( false , false ) ]
18+ public void NoCommandLineArgumentsCrashesParser_Issue_12 ( bool required , bool outcome )
19+ {
20+ var parser = new CommandLineParser < OptionsModelIssue_12 > ( ) ;
21+
22+ parser . Configure ( opt => opt . Test )
23+ . Name ( "-1" )
24+ . Default ( 1 )
25+ . Required ( required ) ;
26+
27+ var parsed = parser . Parse ( new [ ] { "app.exe" } ) ;
28+
29+ Assert . NotNull ( parsed ) ;
30+
31+ Assert . Equal ( outcome , parsed . HasErrors ) ;
32+ }
33+
34+ private class OptionsModelIssue_12
35+ {
36+ public int Test { get ; set ; }
37+ }
38+ }
39+ }
Original file line number Diff line number Diff line change 1- <Project Sdk =" Microsoft.NET.Sdk" >
1+ <Project Sdk =" Microsoft.NET.Sdk" >
22
33 <PropertyGroup >
44 <TargetFramework >netstandard2.0</TargetFramework >
55 <RootNamespace >MatthiWare.CommandLine</RootNamespace >
66 <PackageId >MatthiWare.CommandLineParser</PackageId >
7- <Version >0.1.2 </Version >
7+ <Version >0.1.3 </Version >
88 <Authors >Matthias Beerens</Authors >
99 <Company >MatthiWare</Company >
1010 <Product >Command Line Parser</Product >
Original file line number Diff line number Diff line change 22<package >
33 <metadata >
44 <id >MatthiWare.CommandLineParser</id >
5- <version >0.1.2 </version >
5+ <version >0.1.3 </version >
66 <title >CommandLineParser.Core</title >
77 <authors >Matthias Beerens</authors >
88 <owners >Matthiee</owners >
99 <licenseUrl >https://github.com/MatthiWare/CommandLineParser.Core/blob/master/LICENSE</licenseUrl >
1010 <projectUrl >https://github.com/MatthiWare/CommandLineParser.Core</projectUrl >
1111 <requireLicenseAcceptance >false</requireLicenseAcceptance >
1212 <description >
13- Command Line Parser for .Net Core written in .Net Standard.
14-
15- Configuration is done using an option class and/or fluent api.
16- This library allows to add commands with their own set of options as well.
17-
18- For sample app and documentation visit: https://github.com/MatthiWare/CommandLineParser.Core
19- </description >
13+ Command Line Parser for .Net Core written in .Net Standard.
14+
15+ Configuration is done through a option model class using attributes or fluent API can be used to configure the properties of the class.
16+ This library allows to add commands with their own set of options as well.
17+ </description >
2018 <summary >A simple, light-weight and strongly typed command line parser. Configuration using fluent API and an options class. </summary >
21- <releaseNotes >Adds documentation .</releaseNotes >
19+ <releaseNotes >Fixed issue where parser would crash when no arguments are supplied .</releaseNotes >
2220 <copyright >Copyright Matthias Beerens 2018</copyright >
2321 <tags >commandline parser commandline-parser</tags >
2422 </metadata >
Original file line number Diff line number Diff line change @@ -51,6 +51,8 @@ private void Parse(IEnumerable<ICommandLineCommand> list)
5151 {
5252 int idx = FindIndex ( item ) ;
5353
54+ if ( idx == - 1 ) continue ; // not found issue #12
55+
5456 SetArgumentUsed ( idx , item ) ;
5557 }
5658 }
@@ -61,6 +63,8 @@ private void ParseCommands(IEnumerable<CommandLineCommandBase> cmds)
6163 {
6264 int idx = FindIndex ( cmd ) ;
6365
66+ if ( idx == - 1 ) continue ;
67+
6468 SetArgumentUsed ( idx , cmd ) ;
6569
6670 foreach ( var option in cmd . Options )
Original file line number Diff line number Diff line change 66 </PropertyGroup >
77
88 <ItemGroup >
9- <PackageReference Include =" MatthiWare.CommandLineParser" Version =" 0.1.1 " />
9+ <PackageReference Include =" MatthiWare.CommandLineParser" Version =" 0.1.3 " />
1010 </ItemGroup >
1111
1212</Project >
You can’t perform that action at this time.
0 commit comments