Skip to content

Commit 0f2c2f1

Browse files
authored
Merge pull request #16 from jpdillingham/dev
Removed fixes and tests for multi-value arguments mixing short and long names. Added StyleCop analysis settings.
2 parents 2c50367 + 7e401d7 commit 0f2c2f1

21 files changed

+423
-219
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ AppPackages/
164164

165165
# Others
166166
ClientBin/
167-
[Ss]tyle[Cc]op.*
168167
~$*
169168
*~
170169
*.dbmdl

Examples/Examples.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<DefineConstants>DEBUG;TRACE</DefineConstants>
2323
<ErrorReport>prompt</ErrorReport>
2424
<WarningLevel>4</WarningLevel>
25+
<CodeAnalysisRuleSet>Examples.ruleset</CodeAnalysisRuleSet>
26+
<DocumentationFile>bin\Debug\Examples.XML</DocumentationFile>
27+
<RunCodeAnalysis>true</RunCodeAnalysis>
2528
</PropertyGroup>
2629
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2730
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -31,6 +34,7 @@
3134
<DefineConstants>TRACE</DefineConstants>
3235
<ErrorReport>prompt</ErrorReport>
3336
<WarningLevel>4</WarningLevel>
37+
<CodeAnalysisRuleSet>Examples.ruleset</CodeAnalysisRuleSet>
3438
</PropertyGroup>
3539
<ItemGroup>
3640
<Reference Include="System" />
@@ -48,13 +52,21 @@
4852
</ItemGroup>
4953
<ItemGroup>
5054
<None Include="App.config" />
55+
<None Include="Examples.ruleset" />
56+
<None Include="packages.config" />
57+
<AdditionalFiles Include="stylecop.json" />
5158
</ItemGroup>
5259
<ItemGroup>
5360
<ProjectReference Include="..\Utility.CommandLine.Arguments\Utility.CommandLine.Arguments.csproj">
5461
<Project>{b739dd22-4bd3-4d17-a351-33d129e9fe30}</Project>
5562
<Name>Utility.CommandLine.Arguments</Name>
5663
</ProjectReference>
5764
</ItemGroup>
65+
<ItemGroup>
66+
<Analyzer Include="..\packages\StyleCop.Analyzers.1.1.0-beta001\analyzers\dotnet\cs\Newtonsoft.Json.dll" />
67+
<Analyzer Include="..\packages\StyleCop.Analyzers.1.1.0-beta001\analyzers\dotnet\cs\StyleCop.Analyzers.CodeFixes.dll" />
68+
<Analyzer Include="..\packages\StyleCop.Analyzers.1.1.0-beta001\analyzers\dotnet\cs\StyleCop.Analyzers.dll" />
69+
</ItemGroup>
5870
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5971
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
6072
Other similar extension points exist, see Microsoft.Common.targets.

Examples/Examples.ruleset

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RuleSet Name="Rules for Examples" Description="Code analysis rules for Examples.csproj." ToolsVersion="14.0">
3+
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
4+
<Rule Id="CA1001" Action="Warning" />
5+
<Rule Id="CA1009" Action="Warning" />
6+
<Rule Id="CA1016" Action="Warning" />
7+
<Rule Id="CA1033" Action="Warning" />
8+
<Rule Id="CA1049" Action="Warning" />
9+
<Rule Id="CA1060" Action="Warning" />
10+
<Rule Id="CA1061" Action="Warning" />
11+
<Rule Id="CA1063" Action="Warning" />
12+
<Rule Id="CA1065" Action="Warning" />
13+
<Rule Id="CA1301" Action="Warning" />
14+
<Rule Id="CA1400" Action="Warning" />
15+
<Rule Id="CA1401" Action="Warning" />
16+
<Rule Id="CA1403" Action="Warning" />
17+
<Rule Id="CA1404" Action="Warning" />
18+
<Rule Id="CA1405" Action="Warning" />
19+
<Rule Id="CA1410" Action="Warning" />
20+
<Rule Id="CA1415" Action="Warning" />
21+
<Rule Id="CA1821" Action="Warning" />
22+
<Rule Id="CA1900" Action="Warning" />
23+
<Rule Id="CA1901" Action="Warning" />
24+
<Rule Id="CA2002" Action="Warning" />
25+
<Rule Id="CA2100" Action="Warning" />
26+
<Rule Id="CA2101" Action="Warning" />
27+
<Rule Id="CA2108" Action="Warning" />
28+
<Rule Id="CA2111" Action="Warning" />
29+
<Rule Id="CA2112" Action="Warning" />
30+
<Rule Id="CA2114" Action="Warning" />
31+
<Rule Id="CA2116" Action="Warning" />
32+
<Rule Id="CA2117" Action="Warning" />
33+
<Rule Id="CA2122" Action="Warning" />
34+
<Rule Id="CA2123" Action="Warning" />
35+
<Rule Id="CA2124" Action="Warning" />
36+
<Rule Id="CA2126" Action="Warning" />
37+
<Rule Id="CA2131" Action="Warning" />
38+
<Rule Id="CA2132" Action="Warning" />
39+
<Rule Id="CA2133" Action="Warning" />
40+
<Rule Id="CA2134" Action="Warning" />
41+
<Rule Id="CA2137" Action="Warning" />
42+
<Rule Id="CA2138" Action="Warning" />
43+
<Rule Id="CA2140" Action="Warning" />
44+
<Rule Id="CA2141" Action="Warning" />
45+
<Rule Id="CA2146" Action="Warning" />
46+
<Rule Id="CA2147" Action="Warning" />
47+
<Rule Id="CA2149" Action="Warning" />
48+
<Rule Id="CA2200" Action="Warning" />
49+
<Rule Id="CA2202" Action="Warning" />
50+
<Rule Id="CA2207" Action="Warning" />
51+
<Rule Id="CA2212" Action="Warning" />
52+
<Rule Id="CA2213" Action="Warning" />
53+
<Rule Id="CA2214" Action="Warning" />
54+
<Rule Id="CA2216" Action="Warning" />
55+
<Rule Id="CA2220" Action="Warning" />
56+
<Rule Id="CA2229" Action="Warning" />
57+
<Rule Id="CA2231" Action="Warning" />
58+
<Rule Id="CA2232" Action="Warning" />
59+
<Rule Id="CA2235" Action="Warning" />
60+
<Rule Id="CA2236" Action="Warning" />
61+
<Rule Id="CA2237" Action="Warning" />
62+
<Rule Id="CA2238" Action="Warning" />
63+
<Rule Id="CA2240" Action="Warning" />
64+
<Rule Id="CA2241" Action="Warning" />
65+
<Rule Id="CA2242" Action="Warning" />
66+
</Rules>
67+
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
68+
<Rule Id="SA1124" Action="None" />
69+
<Rule Id="SA1633" Action="None" />
70+
</Rules>
71+
</RuleSet>

Examples/Program.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,39 @@ internal class Program
1212
{
1313
#region Private Properties
1414

15+
/// <summary>
16+
/// Gets or sets a value indicating whether the Bool argument was supplied.
17+
/// </summary>
1518
[Argument('b', "boolean")]
1619
private static bool Bool { get; set; }
1720

21+
/// <summary>
22+
/// Gets or sets the value of the Double argument.
23+
/// </summary>
1824
[Argument('f', "float")]
1925
private static double Double { get; set; }
2026

27+
/// <summary>
28+
/// Gets or sets the value of the Int argument
29+
/// </summary>
2130
[Argument('i', "integer")]
2231
private static int Int { get; set; }
2332

33+
/// <summary>
34+
/// Gets or sets the value of the List argument.
35+
/// </summary>
2436
[Argument('l', "list")]
2537
private static List<int> List { get; set; }
2638

39+
/// <summary>
40+
/// Gets or sets the list of operands.
41+
/// </summary>
2742
[Operands]
2843
private static string[] Operands { get; set; }
2944

45+
/// <summary>
46+
/// Gets or sets the String argument.
47+
/// </summary>
3048
[Argument('s', "string")]
3149
private static string String { get; set; }
3250

@@ -41,7 +59,7 @@ internal class Program
4159
private static void Main(string[] args)
4260
{
4361
// enable ctrl+c
44-
Console.CancelKeyPress += delegate
62+
Console.CancelKeyPress += (o, e) =>
4563
{
4664
Environment.Exit(1);
4765
};
@@ -92,7 +110,7 @@ private static void Print(string commandLine)
92110
Console.WriteLine("Bool\t\t" + Bool);
93111
Console.WriteLine("Int\t\t" + Int);
94112
Console.WriteLine("Double\t\t" + Double);
95-
Console.WriteLine("List\t\t" + String.Join(",", List.Select(o => o.ToString()).ToArray()));
113+
Console.WriteLine("List\t\t" + string.Join(",", List.Select(o => o.ToString())?.ToArray()));
96114

97115
Console.WriteLine("\r\nOperands\n-------");
98116

@@ -111,6 +129,7 @@ private static void Reset()
111129
Bool = false;
112130
Int = 0;
113131
Double = 0;
132+
List = new List<int>();
114133
}
115134

116135
#endregion Private Methods
Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
using System.Reflection;
2-
using System.Runtime.CompilerServices;
32
using System.Runtime.InteropServices;
43

5-
// General Information about an assembly is controlled through the following
6-
// set of attributes. Change these attribute values to modify the information
7-
// associated with an assembly.
84
[assembly: AssemblyTitle("Examples")]
95
[assembly: AssemblyDescription("")]
106
[assembly: AssemblyConfiguration("")]
@@ -13,24 +9,7 @@
139
[assembly: AssemblyCopyright("Copyright © 2017")]
1410
[assembly: AssemblyTrademark("")]
1511
[assembly: AssemblyCulture("")]
16-
17-
// Setting ComVisible to false makes the types in this assembly not visible
18-
// to COM components. If you need to access a type in this assembly from
19-
// COM, set the ComVisible attribute to true on that type.
2012
[assembly: ComVisible(false)]
21-
22-
// The following GUID is for the ID of the typelib if this project is exposed to COM
2313
[assembly: Guid("45d85bd0-089d-4a40-9780-f23baf2eb221")]
24-
25-
// Version information for an assembly consists of the following four values:
26-
//
27-
// Major Version
28-
// Minor Version
29-
// Build Number
30-
// Revision
31-
//
32-
// You can specify all the values or you can default the Build and Revision Numbers
33-
// by using the '*' as shown below:
34-
// [assembly: AssemblyVersion("1.0.*")]
3514
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]
15+
[assembly: AssemblyFileVersion("1.0.0.0")]

Examples/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="StyleCop.Analyzers" version="1.1.0-beta001" targetFramework="net452" developmentDependency="true" />
4+
</packages>

Examples/stylecop.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
3+
"settings": {
4+
"orderingRules": {
5+
"systemUsingDirectivesFirst": true,
6+
"usingDirectivesPlacement": "outsideNamespace"
7+
},
8+
"maintainabilityRules": {
9+
"topLevelTypes": [ "class", "delegate", "enum", "interface" ]
10+
},
11+
"documentationRules": {
12+
"documentPrivateElements": true,
13+
"documentPrivateFields": true
14+
}
15+
}
16+
}

README.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ internal class Program
4141
private static int Int { get; set; }
4242

4343
[Argument('s', "string")]
44-
private static string String { get; set; }
44+
private static string[] String { get; set; }
4545

4646
[Operands]
4747
private static string[] Operands { get; set; }
@@ -50,11 +50,15 @@ internal class Program
5050
{
5151
Arguments.Populate();
5252

53-
Console.WriteLine("String: " + String);
5453
Console.WriteLine("Bool: " + Bool);
5554
Console.WriteLine("Int: " + Int);
5655
Console.WriteLine("Double: " + Double);
5756

57+
foreach (string s in String)
58+
{
59+
Console.WriteLine("String: " + s);
60+
}
61+
5862
foreach (string operand in Operands)
5963
{
6064
Console.WriteLine("\r\n Operand:" + operand);
@@ -159,6 +163,20 @@ c | foo
159163
hello | world
160164
new | slashes are ok too
161165

166+
### Multiple Values
167+
168+
Arguments can accept multiple values, and when parsed a ```List<object>``` is returned if more than one value is specified. When using
169+
the ```Populate()``` method, the underlying property for an argument accepting multiple values must be an array or List, otherwise
170+
an ```InvalidCastException``` is thrown.
171+
172+
#### Example
173+
174+
```--list 1 --list 2 --list 3```
175+
176+
Key | Value
177+
--- | ---
178+
list | 1,2,3
179+
162180
### Operands
163181

164182
Any text in the string that doesn't match the argument-value format is considered an operand. Any text which appears after a double-hyphen ```--```, not enclosed in single or double quotes, and with spaces on either side,
@@ -222,7 +240,10 @@ Use the ```Argument``` attribute to designate properties to be populated. The c
222240
Note that the name of the property doesn't matter; only the attribute values are used to match an argument key to a property.
223241

224242
The Type of the property does matter; the code attempts to convert argument values from string to the specified Type, and if the conversion fails
225-
an ```ArgumentException``` is thrown.
243+
an ```ArgumentException``` is thrown.
244+
245+
Properties can accept lists of parameters, as long as they are backed by an array or ```List<>```. Specifying multiple parameters for an argument backed
246+
by an atomic Type (e.g. not an array or List) will result in an ```InvalidCastException```.
226247

227248
The ```Operands``` property accepts no parameters. If the property type is not ```string[]``` or ```List<string>```, an
228249
```InvalidCastException``` will be thrown.
@@ -239,16 +260,20 @@ private static integer MyNumber { get; set; }
239260
[Argument('b', "bool")]
240261
private static bool TrueOrFalse { get; set; }
241262

263+
[Argument('l', "list")]
264+
private static string[] List { get; set; }
265+
242266
[Operands]
243267
private static List<string> Operands { get; set; }
244268
```
245269

246-
Given the argument string ```-bf "bar" --number=5```, the resulting property values would be as follows:
270+
Given the argument string ```-bf "bar" --number=5 --list 1 --list 2```, the resulting property values would be as follows:
247271

248272
Property | Value
249273
--- | ---
250274
Foo | bar
251275
MyNumber | 5
252276
TrueOrFalse | true
277+
List | 1,2
253278

254279

0 commit comments

Comments
 (0)