diff --git a/src/CLIParser/ArgumentMetadata.cs b/src/CLIParser/ArgumentMetadata.cs
index 1cfac07..0e9bbe7 100644
--- a/src/CLIParser/ArgumentMetadata.cs
+++ b/src/CLIParser/ArgumentMetadata.cs
@@ -35,23 +35,23 @@ namespace MASES.CLIParser
public enum ArgumentPrefix
{
///
- /// Represent an argument without a prefix
+ /// Represents an argument without a prefix
///
None = 0x0,
///
- /// Represent a "-"
+ /// Represents a "-"
///
Dash = 0x1,
///
- /// Represent a "--"
+ /// Represents a "--"
///
DoubleDash = 0x2,
///
- /// Represent a "/"
+ /// Represents a "/"
///
Slash = 0x4,
///
- /// Represent a custom prefix
+ /// Represents a custom prefix
///
Custom = 0x8,
}
@@ -69,7 +69,7 @@ public enum ArgumentType
///
KeyValue,
///
- /// Reperesent an argument whose value if the next argument
+ /// Represents an argument whose value if the next argument
///
Double
}
@@ -83,11 +83,11 @@ public enum ArgumentValueType
///
Free,
///
- /// Represent a possible value into an array
+ /// Represents a possible value into an array
///
Array,
///
- /// Represent a range of values
+ /// Represents a range of values
///
Range
}
@@ -169,10 +169,14 @@ public interface IArgumentMetadata
///
object MinValue { get; set; }
///
- /// The ,aximum value for the argument if is
+ /// The maximum value for the argument if is
///
object MaxValue { get; set; }
///
+ /// An to cross check multiple values. If something is not correct during check an shall be raised.
+ ///
+ Action> CrossCheck { get; set; }
+ ///
/// The of the parameter.
///
Type DataType { get; }
@@ -291,6 +295,8 @@ internal ArgumentMetadataBase()
///
public virtual object MaxValue { get; set; }
///
+ public virtual Action> CrossCheck { get; set; }
+ ///
public virtual Type DataType { get; protected set; }
}
@@ -316,6 +322,7 @@ public ArgumentMetadataParsed(IArgumentMetadata reference)
ArrayValues = reference.ArrayValues;
MinValue = reference.MinValue;
MaxValue = reference.MaxValue;
+ CrossCheck = reference.CrossCheck;
DataType = reference.DataType;
}
diff --git a/src/CLIParser/CLIParser.cs b/src/CLIParser/CLIParser.cs
index adedb36..c3a91f6 100644
--- a/src/CLIParser/CLIParser.cs
+++ b/src/CLIParser/CLIParser.cs
@@ -310,6 +310,10 @@ public static Parser CreateInstance(Settings settings = null)
///
public Settings Settings { get; private set; }
///
+ /// The arguments in command-line not parsed, i.e. the possible extra arguments to be used from the application for other scopes
+ ///
+ public string[] UnparsedArgs { get; private set; }
+ ///
/// Available for parsing
///
public IReadOnlyList Arguments { get { return new List(arguments.Values); } }
@@ -378,6 +382,16 @@ public IEnumerable Parse(string[] args)
throw new ArgumentException(string.Format("Parameter{0} {1} are not managed", lstArgs.Count == 1 ? string.Empty : "s", string.Join(", ", lstArgs)));
}
+ foreach (var item in parsedArgs.Values)
+ {
+ if (item.CrossCheck != null)
+ {
+ item.CrossCheck(parsedArgs.Values);
+ }
+ }
+
+ UnparsedArgs = new List(lstArgs).ToArray();
+
return parsedArgs.Values;
}
diff --git a/src/CLIParser/CLIParser.csproj b/src/CLIParser/CLIParser.csproj
index cd0d2a3..bc62c54 100644
--- a/src/CLIParser/CLIParser.csproj
+++ b/src/CLIParser/CLIParser.csproj
@@ -8,7 +8,7 @@
MASES s.r.l.
MASES s.r.l.
MASES s.r.l.
- 2.1.2.0
+ 2.2.0.0
CLIParser
true
net461;netcoreapp3.1;net5.0;net5.0-windows
@@ -28,6 +28,14 @@
true
..\Common\CLIParser.snk
+
+
+ $([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)'))
+
+
+
+
+
true
diff --git a/tests/CLIParserTest/CLIParserTest.csproj b/tests/CLIParserTest/CLIParserTest.csproj
index aa0a851..73433e4 100644
--- a/tests/CLIParserTest/CLIParserTest.csproj
+++ b/tests/CLIParserTest/CLIParserTest.csproj
@@ -9,7 +9,7 @@
Copyright © MASES s.r.l. 2021
MASES s.r.l.
MASES s.r.l.
- 2.1.2.0
+ 2.2.0.0
net461;netcoreapp3.1;net5.0;net5.0-windows
..\..\bin\
diff --git a/tests/CLIParserTest/Program.cs b/tests/CLIParserTest/Program.cs
index 9539bd3..63fa378 100644
--- a/tests/CLIParserTest/Program.cs
+++ b/tests/CLIParserTest/Program.cs
@@ -24,6 +24,7 @@
using MASES.CLIParser;
using System;
+using System.Collections.Generic;
namespace MASES.CLIParserTest
{
@@ -37,88 +38,101 @@ public enum MyValues
Third = 0x4
};
+ static void crossCheckExample(IEnumerable args)
+ {
+ if (!args.Exist("range")) throw new ArgumentException("range is mandatory for test.");
+ }
+
static void Main(string[] args)
{
- Parser parser = Parser.CreateInstance(new Settings()
+ try
{
- CheckUnwanted = false
- });
+ Parser parser = Parser.CreateInstance(new Settings()
+ {
+ CheckUnwanted = false
+ });
- new ArgumentMetadata(parser)
- {
- Name = "enum",
- Default = MyValues.First,
- Help = "this is an enum test",
- Type = ArgumentType.Double,
- }.Add();
- parser.Add(new ArgumentMetadata()
- {
- Name = "test",
- ShortName = "tst",
- Help = "this is a test",
- Type = ArgumentType.Double,
- ValueType = ArgumentValueType.Free,
- });
- parser.Add(new ArgumentMetadata(parser)
- {
- Name = "range",
- Default = 9,
- Type = ArgumentType.Double,
- ValueType = ArgumentValueType.Range,
- MinValue = 2,
- MaxValue = 10,
- });
- parser.Add(new ArgumentMetadata(parser)
- {
- Name = "multivalue",
- Type = ArgumentType.Double,
- IsMultiValue = true,
- Default = new string[] { "a", "b" }
- });
- parser.Add(new ArgumentMetadata(parser)
- {
- Name = "myval",
- Type = ArgumentType.Single,
- });
- parser.Add(new ArgumentMetadata(parser)
- {
- Name = "MyParam",
- Type = ArgumentType.Double,
- });
- parser.Add(new ArgumentMetadata(parser)
- {
- Name = "MyParam2",
- Type = ArgumentType.Double,
- });
+ new ArgumentMetadata(parser)
+ {
+ Name = "enum",
+ Default = MyValues.First,
+ Help = "this is an enum test",
+ Type = ArgumentType.Double,
+ }.Add();
+ parser.Add(new ArgumentMetadata()
+ {
+ Name = "test",
+ ShortName = "tst",
+ Help = "this is a test",
+ Type = ArgumentType.Double,
+ CrossCheck = crossCheckExample,
+ ValueType = ArgumentValueType.Free,
+ });
+ parser.Add(new ArgumentMetadata(parser)
+ {
+ Name = "range",
+ Default = 9,
+ Type = ArgumentType.Double,
+ ValueType = ArgumentValueType.Range,
+ MinValue = 2,
+ MaxValue = 10,
+ });
+ parser.Add(new ArgumentMetadata(parser)
+ {
+ Name = "multivalue",
+ Type = ArgumentType.Double,
+ IsMultiValue = true,
+ Default = new string[] { "a", "b" }
+ });
+ parser.Add(new ArgumentMetadata(parser)
+ {
+ Name = "myval",
+ Type = ArgumentType.Single,
+ });
+ parser.Add(new ArgumentMetadata(parser)
+ {
+ Name = "MyParam",
+ Type = ArgumentType.Double,
+ });
+ parser.Add(new ArgumentMetadata(parser)
+ {
+ Name = "MyParam2",
+ Type = ArgumentType.Double,
+ });
- var result = parser.Parse(args);
+ var result = parser.Parse(args);
- var fileInfo = parser.FromFile(result);
+ var fileInfo = parser.FromFile(result);
- parser.Override(result, fileInfo);
+ parser.Override(result, fileInfo);
- var noFile = parser.RemoveFile(result);
+ var noFile = parser.RemoveFile(result);
- foreach (var item in parser.Exists(noFile))
- {
- if (item.Name == "enum")
+ foreach (var item in parser.Exists(noFile))
{
- Console.WriteLine("Testing method extension: {0} is {1}", item.Name, item.Get());
- }
+ if (item.Name == "enum")
+ {
+ Console.WriteLine("Testing method extension: {0} is {1}", item.Name, item.Get());
+ }
- if (!item.IsMultiValue)
- {
- Console.WriteLine("{0} is {1}", item.Name, item.Value);
+ if (!item.IsMultiValue)
+ {
+ Console.WriteLine("{0} is {1}", item.Name, item.Value);
+ }
+ else
+ {
+ Console.WriteLine("{0} is {1}", item.Name, string.Join(", ", (object[])item.Value));
+ }
}
- else
+
+ foreach (var item in parser.NotExists(noFile))
{
- Console.WriteLine("{0} is {1}", item.Name, string.Join(", ", (object[])item.Value));
+ Console.WriteLine("{0} not exist", item.Name);
}
}
-
- foreach (var item in parser.NotExists(noFile))
+ catch (Exception e)
{
- Console.WriteLine("{0} not exist", item.Name);
+ Console.WriteLine(e.Message);
}
}
}