diff --git a/CHANGELOG.md b/CHANGELOG.md
index eea8ad12..fd03d221 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,31 @@ All notable changes to this project will be documented in this file.
CommandLineParser project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [2.9.5] 2026-03-17
+
+###
+- got rid of the rest of the F# support
+- lots of ReSharper fixes
+
+## [2.9.4] 2026-03-17
+
+###
+- Lots of little ReSharper fixes
+- Ripped out most of the F# support
+
+## [2.9.3-unixwiz]
+
+###
+- Updated frameworks, went from "netstandard2.0;net40;net45;net461" to "net8.0".
+- Deleted LangVersion = 8.0 (way too old)
+
+## [2.9.2-unixwiz]
+
+###
+- First Unixwiz private build
+- Ensured that OptionAttribute and ValueAttribute classes are not sealed.
+- Started mucking w/ the package version stuff
+
## [2.9.0-preview2]
### Added
diff --git a/CommandLine.sln.DotSettings b/CommandLine.sln.DotSettings
new file mode 100644
index 00000000..f29b1d5f
--- /dev/null
+++ b/CommandLine.sln.DotSettings
@@ -0,0 +1,2 @@
+
+ True
\ No newline at end of file
diff --git a/README.md b/README.md
index 79a16fa7..1096772d 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,19 @@
[](https://www.nuget.org/packages/CommandLineParser/)
[](https://gitter.im/gsscoder/commandline?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
+# Unixwiz.net update
+
+This is a private, independently-maintained fork of the excellent CommandLineParser package
+for modern .NET applications, and has dropped support for anything but recent .NET versions.
+We have an application that required a change - un-sealing the "OptionValue" and "ValueAttribute"
+classes - and needed to share this with a small circle of customers.
+
+Sorry, FSharp and .netstandard support has been removed. The docs below will be edited at some
+point to ensure that this README.md is not lying.
+
+Do not enable `GeneratePackageOnBuild` - it interferes with expected behavior of `dotnet pack -c Release`
+after a clean build and caused missing-output packaging failures.
+
# Command Line Parser Library for CLR and NetStandard
**Note:** the API surface has changed since v1.9.x and earlier. If you are looking for documentation on v1.9.x, please see [stable-1.9.71.2](https://github.com/gsscoder/commandline/tree/stable-1.9.71.2)
diff --git a/src/CommandLine/BaseAttribute.cs b/src/CommandLine/BaseAttribute.cs
index be0a3826..88be9324 100644
--- a/src/CommandLine/BaseAttribute.cs
+++ b/src/CommandLine/BaseAttribute.cs
@@ -11,7 +11,6 @@ public abstract class BaseAttribute : Attribute
{
private int min;
private int max;
- private object @default;
private Infrastructure.LocalizableAttributeProperty helpText;
private string metaValue;
private Type resourceType;
@@ -44,12 +43,12 @@ public bool Required
/// If not set, no lower range is enforced.
public int Min
{
- get { return min; }
+ get => min;
set
{
if (value < 0)
{
- throw new ArgumentNullException("value");
+ throw new ArgumentNullException(nameof(value));
}
min = value;
@@ -63,12 +62,12 @@ public int Min
/// If not set, no upper range is enforced.
public int Max
{
- get { return max; }
+ get => max;
set
{
if (value < 0)
{
- throw new ArgumentNullException("value");
+ throw new ArgumentNullException(nameof(value));
}
max = value;
@@ -78,14 +77,7 @@ public int Max
///
/// Gets or sets mapped property default value.
///
- public object Default
- {
- get { return @default; }
- set
- {
- @default = value;
- }
- }
+ public object Default { get; set; }
///
/// Gets or sets a short description of this command line option. Usually a sentence summary.
@@ -93,7 +85,7 @@ public object Default
public string HelpText
{
get => helpText.Value??string.Empty;
- set => helpText.Value = value ?? throw new ArgumentNullException("value");
+ set => helpText.Value = value ?? throw new ArgumentNullException(nameof(value));
}
///
@@ -101,16 +93,8 @@ public string HelpText
///
public string MetaValue
{
- get { return metaValue; }
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException("value");
- }
-
- metaValue = value;
- }
+ get => metaValue;
+ set => metaValue = value ?? throw new ArgumentNullException(nameof(value));
}
///
@@ -127,12 +111,8 @@ public bool Hidden
///
public Type ResourceType
{
- get { return resourceType; }
- set
- {
- resourceType =
- helpText.ResourceType = value;
- }
+ get => resourceType;
+ set => resourceType = helpText.ResourceType = value;
}
}
}
diff --git a/src/CommandLine/CommandLine.csproj b/src/CommandLine/CommandLine.csproj
index 04496eb8..bc7d2cd4 100644
--- a/src/CommandLine/CommandLine.csproj
+++ b/src/CommandLine/CommandLine.csproj
@@ -3,36 +3,29 @@
CommandLineLibrary
- netstandard2.0;net40;net45;net461
+ net8.0$(DefineConstants);CSX_EITHER_INTERNAL;CSX_REM_EITHER_BEYOND_2;CSX_ENUM_INTERNAL;ERRH_INTERNAL;CSX_MAYBE_INTERNAL;CSX_REM_EITHER_FUNC;CSX_REM_CRYPTORAND;ERRH_ADD_MAYBE_METHODS
- $(DefineConstants);SKIP_FSHARPtrue..\..\CommandLine.snktrue
- CommandLineParser
- CommandLineParser.FSharp
- gsscoder;nemec;ericnewton76;moh-hassan
- Command Line Parser Library
+ Unixwiz.CommandLineParser
+ gsscoder;nemec;ericnewton76;moh-hassan;SJFriedl
+ Command Line Parser Library - Unixwiz.net fork$(VersionSuffix)
- 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.
+ 2.9.5
+ Terse syntax C# command line parser for .NET. 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 - 2020 Giacomo Stelluti Scala & ContributorsLicense.mdCommandLine20.png
- https://github.com/commandlineparser/commandline
+ https://github.com/SJFriedl/commandlinecommand line;commandline;argument;option;parser;parsing;library;syntax;shell
- https://github.com/commandlineparser/commandline/blob/master/CHANGELOG.md
- true
- 8.0
+ https://github.com/SJFriedl/commandline/blob/master/CHANGELOG.md
+ Falsetruesnupkg
+ Unixwiz.CommandLineParser
-
-
-
-
true
@@ -40,12 +33,6 @@
-
-
-
-
-
-
diff --git a/src/CommandLine/Core/GetoptTokenizer.cs b/src/CommandLine/Core/GetoptTokenizer.cs
index b8c97fc2..0c1dc24e 100644
--- a/src/CommandLine/Core/GetoptTokenizer.cs
+++ b/src/CommandLine/Core/GetoptTokenizer.cs
@@ -3,10 +3,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using CommandLine.Infrastructure;
using CSharpx;
using RailwaySharp.ErrorHandling;
-using System.Text.RegularExpressions;
namespace CommandLine.Core
{
@@ -145,7 +143,7 @@ private static IEnumerable TokenizeShortName(
// First option char that requires a value means we swallow the rest of the string as the value
// But if there is no rest of the string, then instead we swallow the next argument
- string chars = arg.Substring(1);
+ string chars = arg[1..];
int len = chars.Length;
if (len > 0 && Char.IsDigit(chars[0]))
{
@@ -164,7 +162,7 @@ private static IEnumerable TokenizeShortName(
if (i+1 < len)
{
// Rest of this is the value (e.g. "-sfoo" where "-s" is a string-consuming arg)
- yield return Token.Value(chars.Substring(i+1));
+ yield return Token.Value(chars[(i+1)..]);
yield break;
}
else
@@ -192,7 +190,7 @@ private static IEnumerable TokenizeLongName(
Action onUnknownOption,
Action onConsumeNext)
{
- string[] parts = arg.Substring(2).Split(new char[] { '=' }, 2);
+ string[] parts = arg[2..].Split(new char[] { '=' }, 2);
string name = parts[0];
string value = (parts.Length > 1) ? parts[1] : null;
// A parameter like "--stringvalue=" is acceptable, and makes stringvalue be the empty string
diff --git a/src/CommandLine/Core/InstanceBuilder.cs b/src/CommandLine/Core/InstanceBuilder.cs
index f48127b1..10137e26 100644
--- a/src/CommandLine/Core/InstanceBuilder.cs
+++ b/src/CommandLine/Core/InstanceBuilder.cs
@@ -94,7 +94,7 @@ public static ParserResult Build(
var valueSpecPropsResult =
ValueMapper.MapValues(
(from pt in specProps where pt.Specification.IsValue() orderby ((ValueSpecification)pt.Specification).Index select pt),
- valuesPartition,
+ valuesPartition,
(vals, type, isScalar) => TypeConverter.ChangeType(vals, type, isScalar, false, parsingCulture, ignoreValueCase));
var missingValueErrors = from token in errorsPartition
@@ -110,7 +110,7 @@ public static ParserResult Build(
//build the instance, determining if the type is mutable or not.
T instance;
- if(typeInfo.IsMutable() == true)
+ if (typeInfo.IsMutable() == true)
{
instance = BuildMutable(factory, specPropsWithValue, setPropertyErrors);
}
@@ -156,8 +156,8 @@ private static T BuildMutable(Maybe> factory, IEnumerable sp.Value.IsJust(),
+ specPropsWithValue,
+ sp => sp.Value.IsJust(),
sp => sp.Value.FromJustOrFail()
)
);
@@ -173,8 +173,8 @@ private static T BuildMutable(Maybe> factory, IEnumerable sp.Value.IsNothing()
- && sp.Specification.TargetType == TargetType.Sequence
+ sp => sp.Value.IsNothing()
+ && sp.Specification.TargetType == TargetType.Sequence
&& sp.Specification.DefaultValue.MatchNothing(),
sp => sp.Property.PropertyType.GetTypeInfo().GetGenericArguments().Single().CreateEmptyArray()
)
@@ -189,7 +189,7 @@ private static T BuildImmutable(Type typeInfo, Maybe> factory, IEnume
specProps.Select(sp => sp.Property.PropertyType).ToArray()
);
- if(ctor == null)
+ if (ctor == null)
{
throw new InvalidOperationException($"Type {typeInfo.FullName} appears to be immutable, but no constructor found to accept values.");
}
diff --git a/src/CommandLine/Core/InstanceChooser.cs b/src/CommandLine/Core/InstanceChooser.cs
index 72307bf2..97258cab 100644
--- a/src/CommandLine/Core/InstanceChooser.cs
+++ b/src/CommandLine/Core/InstanceChooser.cs
@@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
-using CommandLine.Infrastructure;
using CSharpx;
using RailwaySharp.ErrorHandling;
@@ -141,7 +140,7 @@ private static ParserResult
public static void Match(this Maybe> maybe, Action ifJust, Action ifNothing)
{
- T1 value1;
- T2 value2;
- if (maybe.MatchJust(out value1, out value2)) {
+ if (maybe.MatchJust(out var value1, out var value2)) {
ifJust(value1, value2);
return;
}
@@ -225,8 +212,7 @@ public static void Match(this Maybe> maybe, Action
///
public static bool MatchJust(this Maybe> maybe, out T1 value1, out T2 value2)
{
- Tuple value;
- if (maybe.MatchJust(out value)) {
+ if (maybe.MatchJust(out var value)) {
value1 = value.Item1;
value2 = value.Item2;
return true;
@@ -294,27 +280,24 @@ public static Maybe SelectMany(
///
public static void Do(this Maybe maybe, Action action)
{
- T value;
- if (maybe.MatchJust(out value)) {
+ if (maybe.MatchJust(out var value)) {
action(value);
}
}
///
- /// If contans a value executes an delegate over it.
+ /// If contains a value executes an delegate over it.
///
public static void Do(this Maybe> maybe, Action action)
{
- T1 value1;
- T2 value2;
- if (maybe.MatchJust(out value1, out value2)) {
+ if (maybe.MatchJust(out var value1, out var value2)) {
action(value1, value2);
}
}
#endregion
///
- /// Returns true iffits argument is of the form .
+ /// Returns true if its argument is of the form .
///
public static bool IsJust(this Maybe maybe)
{
@@ -322,7 +305,7 @@ public static bool IsJust(this Maybe maybe)
}
///
- /// Returns true iffits argument is of the form .
+ /// Returns true if its argument is of the form .
///
public static bool IsNothing(this Maybe maybe)
{
@@ -334,8 +317,7 @@ public static bool IsNothing(this Maybe maybe)
///
public static T FromJust(this Maybe maybe)
{
- T value;
- if (maybe.MatchJust(out value)) {
+ if (maybe.MatchJust(out var value)) {
return value;
}
return default(T);
@@ -346,8 +328,7 @@ public static T FromJust(this Maybe maybe)
///
public static T FromJustOrFail(this Maybe maybe, Exception exceptionToThrow = null)
{
- T value;
- if (maybe.MatchJust(out value)) {
+ if (maybe.MatchJust(out var value)) {
return value;
}
throw exceptionToThrow ?? new ArgumentException("Value empty.");
@@ -358,8 +339,7 @@ public static T FromJustOrFail(this Maybe maybe, Exception exceptionToThro
///
public static T GetValueOrDefault(this Maybe maybe, T noneValue)
{
- T value;
- return maybe.MatchJust(out value) ? value : noneValue;
+ return maybe.MatchJust(out var value) ? value : noneValue;
}
///
@@ -367,16 +347,14 @@ public static T GetValueOrDefault(this Maybe maybe, T noneValue)
///
public static T2 MapValueOrDefault(this Maybe maybe, Func func, T2 noneValue)
{
- T1 value1;
- return maybe.MatchJust(out value1) ? func(value1) : noneValue;
+ return maybe.MatchJust(out var value1) ? func(value1) : noneValue;
}
///
/// If contains a values executes a mapping function over it, otherwise returns the value from .
///
public static T2 MapValueOrDefault(this Maybe maybe, Func func, Func noneValueFactory) {
- T1 value1;
- return maybe.MatchJust(out value1) ? func(value1) : noneValueFactory();
+ return maybe.MatchJust(out var value1) ? func(value1) : noneValueFactory();
}
///
@@ -384,11 +362,10 @@ public static T2 MapValueOrDefault(this Maybe maybe, Func fu
///
public static IEnumerable ToEnumerable(this Maybe maybe)
{
- T value;
- if (maybe.MatchJust(out value)) {
+ if (maybe.MatchJust(out var value)) {
return Enumerable.Empty().Concat(new[] { value });
}
return Enumerable.Empty();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/CommandLine/Infrastructure/ErrorHandling.cs b/src/CommandLine/Infrastructure/ErrorHandling.cs
index 8aee4bac..66f2ece2 100644
--- a/src/CommandLine/Infrastructure/ErrorHandling.cs
+++ b/src/CommandLine/Infrastructure/ErrorHandling.cs
@@ -10,6 +10,7 @@
using CSharpx;
#endif
+// ReSharper disable once CheckNamespace
namespace RailwaySharp.ErrorHandling
{
#if !ERRH_INTERNAL
@@ -31,17 +32,12 @@ enum ResultType
#endif
abstract class Result
{
- private readonly ResultType _tag;
-
protected Result(ResultType tag)
{
- _tag = tag;
+ Tag = tag;
}
- public ResultType Tag
- {
- get { return _tag; }
- }
+ public ResultType Tag { get; }
public override string ToString()
{
@@ -81,15 +77,9 @@ public Ok(TSuccess success, IEnumerable messages)
_value = Tuple.Create(success, messages);
}
- public TSuccess Success
- {
- get { return _value.Item1; }
- }
+ public TSuccess Success => _value.Item1;
- public IEnumerable Messages
- {
- get { return _value.Item2; }
- }
+ public IEnumerable Messages => _value.Item2;
}
///
@@ -102,20 +92,13 @@ public IEnumerable Messages
#endif
sealed class Bad : Result
{
- private readonly IEnumerable _messages;
-
public Bad(IEnumerable messages)
: base(ResultType.Bad)
{
- if (messages == null) throw new ArgumentException(nameof(messages));
-
- _messages = messages;
+ Messages = messages ?? throw new ArgumentException(nameof(messages));
}
- public IEnumerable Messages
- {
- get { return _messages; }
- }
+ public IEnumerable Messages { get; }
}
#if !ERRH_INTERNAL
@@ -267,8 +250,7 @@ public static TResult Either(
if (successFunc == null) throw new ArgumentException(nameof(successFunc));
if (failureFunc == null) throw new ArgumentException(nameof(failureFunc));
- var ok = trialResult as Ok;
- if (ok != null) {
+ if (trialResult is Ok ok) {
return successFunc(ok.Success, ok.Messages);
}
var bad = (Bad)trialResult;
@@ -277,7 +259,7 @@ public static TResult Either(
///
/// If the given result is a Success the wrapped value will be returned.
- /// Otherwise the function throws an exception with Failure message of the result.
+ /// Otherwise, the function throws an exception with Failure message of the result.
///
#if ERRH_ENABLE_INLINE_METHODS
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -319,7 +301,7 @@ public static Result MergeMessages(
///
/// If the result is a Success it executes the given function on the value.
- /// Otherwise the exisiting failure is propagated.
+ /// Otherwise, the existing failure is propagated.
///
#if ERRH_ENABLE_INLINE_METHODS
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -353,7 +335,7 @@ public static Result Flatten(
///
/// If the wrapped function is a success and the given result is a success the function is applied on the value.
- /// Otherwise the exisiting error messages are propagated.
+ /// Otherwise, the existing error messages are propagated.
///
#if ERRH_ENABLE_INLINE_METHODS
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -472,8 +454,7 @@ public static void Match(this Result res
if (ifSuccess == null) throw new ArgumentException(nameof(ifSuccess));
if (ifFailure == null) throw new ArgumentException(nameof(ifFailure));
- var ok = result as Ok;
- if (ok != null) {
+ if (result is Ok ok) {
ifSuccess(ok.Success, ok.Messages);
return;
}
@@ -546,7 +527,7 @@ public static Result, TMessage> Flatten
/// If the result is a Success it executes the given Func on the value.
- /// Otherwise the exisiting failure is propagated.
+ /// Otherwise, the existing failure is propagated.
///
#if ERRH_ENABLE_INLINE_METHODS
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -560,7 +541,7 @@ public static Result SelectMany(
///
/// If the result is a Success it executes the given Func on the value.
/// If the result of the Func is a Success it maps it using the given Func.
- /// Otherwise the exisiting failure is propagated.
+ /// Otherwise, the existing failure is propagated.
///
#if ERRH_ENABLE_INLINE_METHODS
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -661,4 +642,4 @@ public static Maybe ToMaybe(this Result)
- .MakeGenericType(type)
- .StaticMethod(
- "Some", value);
- }
-
- public static object None(Type type)
- {
- return typeof(FSharpOption<>)
- .MakeGenericType(type)
- .StaticProperty(
- "None");
- }
-
- public static object ValueOf(object value)
- {
- return typeof(FSharpOption<>)
- .MakeGenericType(GetUnderlyingType(value.GetType()))
- .InstanceProperty(
- "Value", value);
- }
-
- public static bool IsSome(object value)
- {
- return (bool)typeof(FSharpOption<>)
- .MakeGenericType(GetUnderlyingType(value.GetType()))
- .StaticMethod(
- "get_IsSome", value);
- }
- }
-}
\ No newline at end of file
diff --git a/src/CommandLine/Infrastructure/LocalizableAttributeProperty.cs b/src/CommandLine/Infrastructure/LocalizableAttributeProperty.cs
index b8bd1398..c2d55965 100644
--- a/src/CommandLine/Infrastructure/LocalizableAttributeProperty.cs
+++ b/src/CommandLine/Infrastructure/LocalizableAttributeProperty.cs
@@ -17,7 +17,7 @@ public LocalizableAttributeProperty(string propertyName)
public string Value
{
- get { return GetLocalizedValue(); }
+ get => GetLocalizedValue();
set
{
_localizationPropertyInfo = null;
diff --git a/src/CommandLine/Infrastructure/StringBuilderExtensions.cs b/src/CommandLine/Infrastructure/StringBuilderExtensions.cs
index ae4ccbc4..0957d0df 100644
--- a/src/CommandLine/Infrastructure/StringBuilderExtensions.cs
+++ b/src/CommandLine/Infrastructure/StringBuilderExtensions.cs
@@ -73,7 +73,7 @@ public static string SafeToString(this StringBuilder builder)
public static int SafeLength(this StringBuilder builder)
{
- return builder == null ? 0 : builder.Length;
+ return builder?.Length ?? 0;
}
public static StringBuilder TrimEnd(this StringBuilder builder, char c)
diff --git a/src/CommandLine/Infrastructure/StringExtensions.cs b/src/CommandLine/Infrastructure/StringExtensions.cs
index db8aa0bd..c575a86a 100644
--- a/src/CommandLine/Infrastructure/StringExtensions.cs
+++ b/src/CommandLine/Infrastructure/StringExtensions.cs
@@ -50,7 +50,7 @@ public static bool EqualsOrdinalIgnoreCase(this string strA, string strB)
public static int SafeLength(this string value)
{
- return value == null ? 0 : value.Length;
+ return value?.Length ?? 0;
}
public static string JoinTo(this string value, params string[] others)
diff --git a/src/CommandLine/NameInfo.cs b/src/CommandLine/NameInfo.cs
index baf259ef..fa820f18 100644
--- a/src/CommandLine/NameInfo.cs
+++ b/src/CommandLine/NameInfo.cs
@@ -1,7 +1,6 @@
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
using System;
-using CommandLine.Core;
namespace CommandLine
{
@@ -15,48 +14,32 @@ public sealed class NameInfo : IEquatable
/// rather than options.
///
public static readonly NameInfo EmptyName = new NameInfo(string.Empty, string.Empty);
- private readonly string longName;
- private readonly string shortName;
internal NameInfo(string shortName, string longName)
{
- if (shortName == null) throw new ArgumentNullException("shortName");
- if (longName == null) throw new ArgumentNullException("longName");
-
- this.longName = longName;
- this.shortName = shortName;
+ this.LongName = longName ?? throw new ArgumentNullException(nameof(longName));
+ this.ShortName = shortName ?? throw new ArgumentNullException(nameof(shortName));
}
///
/// Gets the short name of the name information.
///
- public string ShortName
- {
- get { return shortName; }
- }
+ public string ShortName { get; }
///
/// Gets the long name of the name information.
///
- public string LongName
- {
- get { return longName; }
- }
+ public string LongName { get; }
///
/// Gets a formatted text with unified name information.
///
- public string NameText
- {
- get
- {
- return ShortName.Length > 0 && LongName.Length > 0
- ? ShortName + ", " + LongName
- : ShortName.Length > 0
- ? ShortName
- : LongName;
- }
- }
+ public string NameText =>
+ ShortName.Length > 0 && LongName.Length > 0
+ ? ShortName + ", " + LongName
+ : ShortName.Length > 0
+ ? ShortName
+ : LongName;
///
/// Determines whether the specified is equal to the current .
@@ -65,8 +48,7 @@ public string NameText
/// true if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
- var other = obj as NameInfo;
- if (other != null)
+ if (obj is NameInfo other)
{
return Equals(other);
}
@@ -98,4 +80,4 @@ public bool Equals(NameInfo other)
return ShortName.Equals(other.ShortName) && LongName.Equals(other.LongName);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/CommandLine/NullInstance.cs b/src/CommandLine/NullInstance.cs
index c2ebd77a..820a2f30 100644
--- a/src/CommandLine/NullInstance.cs
+++ b/src/CommandLine/NullInstance.cs
@@ -3,10 +3,10 @@
namespace CommandLine
{
///
- /// Models a null result when constructing a in a faling verbs scenario.
+ /// Models a null result when constructing a in a failing verbs scenario.
///
public sealed class NullInstance
{
internal NullInstance() { }
}
-}
\ No newline at end of file
+}
diff --git a/src/CommandLine/OptionAttribute.cs b/src/CommandLine/OptionAttribute.cs
index 6ae51dac..01a64f38 100644
--- a/src/CommandLine/OptionAttribute.cs
+++ b/src/CommandLine/OptionAttribute.cs
@@ -10,24 +10,16 @@ namespace CommandLine
/// Models an option specification.
///
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
- public sealed class OptionAttribute : BaseAttribute
+ public class OptionAttribute : BaseAttribute
{
- private readonly string longName;
- private readonly string shortName;
private string setName;
- private bool flagCounter;
- private char separator;
- private string group=string.Empty;
private OptionAttribute(string shortName, string longName) : base()
{
- if (shortName == null) throw new ArgumentNullException("shortName");
- if (longName == null) throw new ArgumentNullException("longName");
-
- this.shortName = shortName;
- this.longName = longName;
+ this.ShortName = shortName ?? throw new ArgumentNullException(nameof(shortName));
+ this.LongName = longName ?? throw new ArgumentNullException(nameof(longName));
setName = string.Empty;
- separator = '\0';
+ Separator = '\0';
}
///
@@ -61,7 +53,7 @@ public OptionAttribute(char shortName, string longName)
///
/// Initializes a new instance of the class.
///
- /// The short name of the option..
+ /// The short name of the option.
public OptionAttribute(char shortName)
: this(shortName.ToOneCharString(), string.Empty)
{
@@ -70,60 +62,37 @@ public OptionAttribute(char shortName)
///
/// Gets long name of this command line option. This name is usually a single english word.
///
- public string LongName
- {
- get { return longName; }
- }
+ public string LongName { get; }
///
/// Gets a short name of this command line option, made of one character.
///
- public string ShortName
- {
- get { return shortName; }
- }
+ public string ShortName { get; }
///
/// Gets or sets the option's mutually exclusive set name.
///
public string SetName
{
- get { return setName; }
- set
- {
- if (value == null) throw new ArgumentNullException("value");
-
- setName = value;
- }
+ get => setName;
+ set => setName = value ?? throw new ArgumentNullException(nameof(value));
}
///
/// If true, this is an int option that counts how many times a flag was set (e.g. "-v -v -v" or "-vvv" would return 3).
/// The property must be of type int (signed 32-bit integer).
///
- public bool FlagCounter
- {
- get { return flagCounter; }
- set { flagCounter = value; }
- }
+ public bool FlagCounter { get; set; }
///
/// When applying attribute to target properties,
/// it allows you to split an argument and consume its content as a sequence.
///
- public char Separator
- {
- get { return separator; }
- set { separator = value; }
- }
+ public char Separator { get; set; }
///
/// Gets or sets the option group name. When one or more options are grouped, at least one of them should have value. Required rules are ignored.
///
- public string Group
- {
- get { return group; }
- set { group = value; }
- }
+ public string Group { get; set; } = string.Empty;
}
}
diff --git a/src/CommandLine/Parser.cs b/src/CommandLine/Parser.cs
index 4301aa52..291a82dc 100644
--- a/src/CommandLine/Parser.cs
+++ b/src/CommandLine/Parser.cs
@@ -37,7 +37,7 @@ public Parser()
/// aspects and behaviors of the parser.
public Parser(Action configuration)
{
- if (configuration == null) throw new ArgumentNullException("configuration");
+ if (configuration == null) throw new ArgumentNullException(nameof(configuration));
settings = new ParserSettings();
configuration(settings);
@@ -61,18 +61,12 @@ internal Parser(ParserSettings settings)
///
/// Gets the singleton instance created with basic defaults.
///
- public static Parser Default
- {
- get { return DefaultParser.Value; }
- }
+ public static Parser Default => DefaultParser.Value;
///
/// Gets the instance that implements in use.
///
- public ParserSettings Settings
- {
- get { return settings; }
- }
+ public ParserSettings Settings => settings;
///
/// Parses a string array of command line arguments constructing values in an instance of type .
@@ -85,7 +79,7 @@ public ParserSettings Settings
/// Thrown if one or more arguments are null.
public ParserResult ParseArguments(IEnumerable args)
{
- if (args == null) throw new ArgumentNullException("args");
+ if (args == null) throw new ArgumentNullException(nameof(args));
var factory = typeof(T).IsMutable()
? Maybe.Just>(Activator.CreateInstance)
@@ -118,9 +112,9 @@ public ParserResult ParseArguments(IEnumerable args)
/// Thrown if one or more arguments are null.
public ParserResult ParseArguments(Func factory, IEnumerable args)
{
- if (factory == null) throw new ArgumentNullException("factory");
- if (!typeof(T).IsMutable()) throw new ArgumentException("factory");
- if (args == null) throw new ArgumentNullException("args");
+ if (factory == null) throw new ArgumentNullException(nameof(factory));
+ if (!typeof(T).IsMutable()) throw new ArgumentException(nameof(factory));
+ if (args == null) throw new ArgumentNullException(nameof(args));
return MakeParserResult(
InstanceBuilder.Build(
@@ -151,9 +145,9 @@ public ParserResult ParseArguments(Func factory, IEnumerable ar
/// All types must expose a parameterless constructor. It's strongly recommended to use a generic overload.
public ParserResult ParseArguments(IEnumerable args, params Type[] types)
{
- if (args == null) throw new ArgumentNullException("args");
- if (types == null) throw new ArgumentNullException("types");
- if (types.Length == 0) throw new ArgumentOutOfRangeException("types");
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (types == null) throw new ArgumentNullException(nameof(types));
+ if (types.Length == 0) throw new ArgumentOutOfRangeException(nameof(types));
return MakeParserResult(
InstanceChooser.Choose(
diff --git a/src/CommandLine/ParserExtensions.cs b/src/CommandLine/ParserExtensions.cs
index 1c78ce9d..1e7d7fe2 100644
--- a/src/CommandLine/ParserExtensions.cs
+++ b/src/CommandLine/ParserExtensions.cs
@@ -25,7 +25,7 @@ public static class ParserExtensions
/// All types must expose a parameterless constructor.
public static ParserResult ParseArguments(this Parser parser, IEnumerable args)
{
- if (parser == null) throw new ArgumentNullException("parser");
+ if (parser == null) throw new ArgumentNullException(nameof(parser));
return parser.ParseArguments(args, new[] { typeof(T1), typeof(T2) });
}
@@ -46,7 +46,7 @@ public static ParserResult ParseArguments(this Parser parser, IE
/// All types must expose a parameterless constructor.
public static ParserResult ParseArguments(this Parser parser, IEnumerable args)
{
- if (parser == null) throw new ArgumentNullException("parser");
+ if (parser == null) throw new ArgumentNullException(nameof(parser));
return parser.ParseArguments(args, new[] { typeof(T1), typeof(T2), typeof(T3) });
}
@@ -68,7 +68,7 @@ public static ParserResult ParseArguments(this Parser parser
/// All types must expose a parameterless constructor.
public static ParserResult ParseArguments(this Parser parser, IEnumerable args)
{
- if (parser == null) throw new ArgumentNullException("parser");
+ if (parser == null) throw new ArgumentNullException(nameof(parser));
return parser.ParseArguments(args, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4) });
}
@@ -91,7 +91,7 @@ public static ParserResult ParseArguments(this Parser pa
/// All types must expose a parameterless constructor.
public static ParserResult ParseArguments(this Parser parser, IEnumerable args)
{
- if (parser == null) throw new ArgumentNullException("parser");
+ if (parser == null) throw new ArgumentNullException(nameof(parser));
return parser.ParseArguments(args, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5) });
}
@@ -115,7 +115,7 @@ public static ParserResult ParseArguments(this Parse
/// All types must expose a parameterless constructor.
public static ParserResult ParseArguments(this Parser parser, IEnumerable args)
{
- if (parser == null) throw new ArgumentNullException("parser");
+ if (parser == null) throw new ArgumentNullException(nameof(parser));
return parser.ParseArguments(args, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6) });
}
@@ -140,7 +140,7 @@ public static ParserResult ParseArguments(this P
/// All types must expose a parameterless constructor.
public static ParserResult ParseArguments(this Parser parser, IEnumerable args)
{
- if (parser == null) throw new ArgumentNullException("parser");
+ if (parser == null) throw new ArgumentNullException(nameof(parser));
return parser.ParseArguments(args, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7) });
}
@@ -166,7 +166,7 @@ public static ParserResult ParseArguments(th
/// All types must expose a parameterless constructor.
public static ParserResult ParseArguments(this Parser parser, IEnumerable args)
{
- if (parser == null) throw new ArgumentNullException("parser");
+ if (parser == null) throw new ArgumentNullException(nameof(parser));
return parser.ParseArguments(args, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8) });
}
@@ -193,7 +193,7 @@ public static ParserResult ParseArgumentsAll types must expose a parameterless constructor.
public static ParserResult ParseArguments(this Parser parser, IEnumerable args)
{
- if (parser == null) throw new ArgumentNullException("parser");
+ if (parser == null) throw new ArgumentNullException(nameof(parser));
return parser.ParseArguments(args, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8),
typeof(T9) });
@@ -222,7 +222,7 @@ public static ParserResult ParseArgumentsAll types must expose a parameterless constructor.
public static ParserResult ParseArguments(this Parser parser, IEnumerable args)
{
- if (parser == null) throw new ArgumentNullException("parser");
+ if (parser == null) throw new ArgumentNullException(nameof(parser));
return parser.ParseArguments(args, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8),
typeof(T9), typeof(T10) });
@@ -252,7 +252,7 @@ public static ParserResult ParseArgumentsAll types must expose a parameterless constructor.
public static ParserResult ParseArguments(this Parser parser, IEnumerable args)
{
- if (parser == null) throw new ArgumentNullException("parser");
+ if (parser == null) throw new ArgumentNullException(nameof(parser));
return parser.ParseArguments(args, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8),
typeof(T9), typeof(T10), typeof(T11) });
@@ -283,7 +283,7 @@ public static ParserResult ParseArgumentsAll types must expose a parameterless constructor.
public static ParserResult ParseArguments(this Parser parser, IEnumerable args)
{
- if (parser == null) throw new ArgumentNullException("parser");
+ if (parser == null) throw new ArgumentNullException(nameof(parser));
return parser.ParseArguments(args, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8),
typeof(T9), typeof(T10), typeof(T11), typeof(T12) });
@@ -315,7 +315,7 @@ public static ParserResult ParseArgumentsAll types must expose a parameterless constructor.
public static ParserResult ParseArguments(this Parser parser, IEnumerable args)
{
- if (parser == null) throw new ArgumentNullException("parser");
+ if (parser == null) throw new ArgumentNullException(nameof(parser));
return parser.ParseArguments(args, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8),
typeof(T9), typeof(T10), typeof(T11), typeof(T12), typeof(T13) });
@@ -348,7 +348,7 @@ public static ParserResult ParseArgumentsAll types must expose a parameterless constructor.
public static ParserResult ParseArguments(this Parser parser, IEnumerable args)
{
- if (parser == null) throw new ArgumentNullException("parser");
+ if (parser == null) throw new ArgumentNullException(nameof(parser));
return parser.ParseArguments(args, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8),
typeof(T9), typeof(T10), typeof(T11), typeof(T12), typeof(T13), typeof(T14) });
@@ -382,7 +382,7 @@ public static ParserResult ParseArgumentsAll types must expose a parameterless constructor.
public static ParserResult ParseArguments(this Parser parser, IEnumerable args)
{
- if (parser == null) throw new ArgumentNullException("parser");
+ if (parser == null) throw new ArgumentNullException(nameof(parser));
return parser.ParseArguments(args, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8),
typeof(T9), typeof(T10), typeof(T11), typeof(T12), typeof(T13), typeof(T14), typeof(T15) });
@@ -417,10 +417,10 @@ public static ParserResult ParseArgumentsAll types must expose a parameterless constructor.
public static ParserResult ParseArguments(this Parser parser, IEnumerable args)
{
- if (parser == null) throw new ArgumentNullException("parser");
+ if (parser == null) throw new ArgumentNullException(nameof(parser));
return parser.ParseArguments(args, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8),
typeof(T9), typeof(T10), typeof(T11), typeof(T12), typeof(T13), typeof(T14), typeof(T15), typeof(T16) });
}
}
-}
\ No newline at end of file
+}
diff --git a/src/CommandLine/ParserResult.cs b/src/CommandLine/ParserResult.cs
index c7c9c833..d74a8efb 100644
--- a/src/CommandLine/ParserResult.cs
+++ b/src/CommandLine/ParserResult.cs
@@ -8,24 +8,15 @@ namespace CommandLine
{
public sealed class TypeInfo
{
- private readonly Type current;
- private readonly IEnumerable choices;
-
private TypeInfo(Type current, IEnumerable choices)
{
- this.current = current;
- this.choices = choices;
+ this.Current = current;
+ this.Choices = choices;
}
- public Type Current
- {
- get { return this.current; }
- }
+ public Type Current { get; }
- public IEnumerable Choices
- {
- get { return this.choices; }
- }
+ public IEnumerable Choices { get; }
internal static TypeInfo Create(Type current)
{
@@ -61,40 +52,31 @@ public enum ParserResultType
/// The type with attributes that define the syntax of parsing rules.
public abstract class ParserResult
{
- private readonly ParserResultType tag;
- private readonly TypeInfo typeInfo;
-
internal ParserResult(IEnumerable errors, TypeInfo typeInfo)
{
- this.tag = ParserResultType.NotParsed;
- this.typeInfo = typeInfo ?? TypeInfo.Create(typeof(T));
- Errors = errors ?? new Error[0];
+ this.Tag = ParserResultType.NotParsed;
+ this.TypeInfo = typeInfo ?? TypeInfo.Create(typeof(T));
+ Errors = errors ?? Array.Empty();
Value = default;
}
internal ParserResult(T value, TypeInfo typeInfo)
{
Value = value ?? throw new ArgumentNullException(nameof(value));
- this.tag = ParserResultType.Parsed;
- this.typeInfo = typeInfo ?? TypeInfo.Create(value.GetType());
- Errors = new Error[0];
+ this.Tag = ParserResultType.Parsed;
+ this.TypeInfo = typeInfo ?? TypeInfo.Create(value.GetType());
+ Errors = Array.Empty();
}
///
/// Parser result type discriminator, defined as enumeration.
///
- public ParserResultType Tag
- {
- get { return this.tag; }
- }
+ public ParserResultType Tag { get; }
- public TypeInfo TypeInfo
- {
- get { return typeInfo; }
- }
+ public TypeInfo TypeInfo { get; }
///
- /// Gets the instance with parsed values. If one or more errors occures, is returned.
+ /// Gets the instance with parsed values. If one or more errors occurs, is returned.
///
public T Value { get; }
diff --git a/src/CommandLine/ParserResultExtensions.cs b/src/CommandLine/ParserResultExtensions.cs
index 66201dbb..a5ddd3b6 100644
--- a/src/CommandLine/ParserResultExtensions.cs
+++ b/src/CommandLine/ParserResultExtensions.cs
@@ -20,8 +20,7 @@ public static partial class ParserResultExtensions
/// The same instance.
public static ParserResult WithParsed(this ParserResult result, Action action)
{
- var parsed = result as Parsed;
- if (parsed != null)
+ if (result is Parsed parsed)
{
action(parsed.Value);
}
@@ -37,8 +36,7 @@ public static ParserResult WithParsed(this ParserResult result, Action<
/// The same instance.
public static ParserResult WithParsed(this ParserResult result, Action action)
{
- var parsed = result as Parsed;
- if (parsed != null)
+ if (result is Parsed parsed)
{
if (parsed.Value is T)
{
@@ -58,8 +56,7 @@ public static ParserResult WithParsed(this ParserResult resul
/// The same instance.
public static ParserResult WithNotParsed(this ParserResult result, Action> action)
{
- var notParsed = result as NotParsed;
- if (notParsed != null)
+ if (result is NotParsed notParsed)
{
action(notParsed.Errors);
}
@@ -79,8 +76,7 @@ public static TResult MapResult(this ParserResult res
Func parsedFunc,
Func, TResult> notParsedFunc)
{
- var parsed = result as Parsed;
- if (parsed != null)
+ if (result is Parsed parsed)
{
return parsedFunc(parsed.Value);
}
@@ -100,8 +96,7 @@ public static TResult MapResult(this ParserResult result,
Func parsedFunc1,
Func, TResult> notParsedFunc)
{
- var parsed = result as Parsed;
- if (parsed != null)
+ if (result is Parsed parsed)
{
if (parsed.Value is T1)
{
@@ -128,8 +123,7 @@ public static TResult MapResult(this ParserResult resul
Func parsedFunc2,
Func, TResult> notParsedFunc)
{
- var parsed = result as Parsed;
- if (parsed != null)
+ if (result is Parsed parsed)
{
if (parsed.Value is T1)
{
@@ -163,8 +157,7 @@ public static TResult MapResult(this ParserResult r
Func parsedFunc3,
Func, TResult> notParsedFunc)
{
- var parsed = result as Parsed;
- if (parsed != null)
+ if (result is Parsed parsed)
{
if (parsed.Value is T1)
{
@@ -205,8 +198,7 @@ public static TResult MapResult(this ParserResult parsedFunc4,
Func, TResult> notParsedFunc)
{
- var parsed = result as Parsed;
- if (parsed != null)
+ if (result is Parsed parsed)
{
if (parsed.Value is T1)
{
@@ -254,8 +246,7 @@ public static TResult MapResult(this ParserResult parsedFunc5,
Func, TResult> notParsedFunc)
{
- var parsed = result as Parsed;
- if (parsed != null)
+ if (result is Parsed parsed)
{
if (parsed.Value is T1)
{
@@ -310,8 +301,7 @@ public static TResult MapResult(this ParserResu
Func parsedFunc6,
Func, TResult> notParsedFunc)
{
- var parsed = result as Parsed;
- if (parsed != null)
+ if (result is Parsed parsed)
{
if (parsed.Value is T1)
{
@@ -373,8 +363,7 @@ public static TResult MapResult(this Parser
Func parsedFunc7,
Func, TResult> notParsedFunc)
{
- var parsed = result as Parsed;
- if (parsed != null)
+ if (result is Parsed parsed)
{
if (parsed.Value is T1)
{
@@ -443,8 +432,7 @@ public static TResult MapResult(this Pa
Func parsedFunc8,
Func, TResult> notParsedFunc)
{
- var parsed = result as Parsed;
- if (parsed != null)
+ if (result is Parsed parsed)
{
if (parsed.Value is T1)
{
@@ -520,8 +508,7 @@ public static TResult MapResult(thi
Func parsedFunc9,
Func, TResult> notParsedFunc)
{
- var parsed = result as Parsed;
- if (parsed != null)
+ if (result is Parsed parsed)
{
if (parsed.Value is T1)
{
@@ -604,8 +591,7 @@ public static TResult MapResult parsedFunc10,
Func, TResult> notParsedFunc)
{
- var parsed = result as Parsed;
- if (parsed != null)
+ if (result is Parsed parsed)
{
if (parsed.Value is T1)
{
@@ -695,8 +681,7 @@ public static TResult MapResult parsedFunc11,
Func, TResult> notParsedFunc)
{
- var parsed = result as Parsed;
- if (parsed != null)
+ if (result is Parsed parsed)
{
if (parsed.Value is T1)
{
@@ -793,8 +778,7 @@ public static TResult MapResult parsedFunc12,
Func, TResult> notParsedFunc)
{
- var parsed = result as Parsed;
- if (parsed != null)
+ if (result is Parsed parsed)
{
if (parsed.Value is T1)
{
@@ -898,8 +882,7 @@ public static TResult MapResult parsedFunc13,
Func, TResult> notParsedFunc)
{
- var parsed = result as Parsed;
- if (parsed != null)
+ if (result is Parsed parsed)
{
if (parsed.Value is T1)
{
@@ -1010,8 +993,7 @@ public static TResult MapResult parsedFunc14,
Func