Parameter name is treated as parameter value
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu trong CommandLine.Core.TokenPartitioner.PartitionTokensByType và tái hiện vấn đề với --option1 --option2 5 bằng ví dụ C# được cung cấp. Theo dõi trạng thái ScalarTokenFound và xác minh rằng tên tùy chọn vô hướng chỉ được giữ lại khi theo sau là một giá trị. Hoàn tất có nghĩa là tùy chọn bắt buộc bị thiếu option1 được báo cáo là lỗi thay vì coi option2 là giá trị của nó.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
If I omit parameter value for one parameter name, next parametername is treated as value of the parameter.
Occurred at v2.9.1 from Nuget.
What I observed
Code:
using System;
using CommandLine;
class Options
{
[Option('a', "option1", Required = true)]
public string Option1 { get; set; }
[Option('b', "option2", Required = false)]
public int option2 { get; set; }
}
class Program
{
static int Main(string[] args)
{
return Parser.Default.ParseArguments<Options>(args)
.MapResult(
options => RunAndReturnExitCode(options),
_ => -1);
}
static int RunAndReturnExitCode(Options options)
{
Console.WriteLine($"option1={options.Option1}, option2={options.option2}");
return 0;
}
}
Command line,
$command --option1 --option2 5
gives the result output,
option1=option2, option2=0
But expected result is to report error with lacking of required "option1".
Suggested fix
In the method "CommandLine.Core.TokenPartitioner.PartitionTokensByType", scalarTokens.add(Scalar nem token) shall be occurred only when the following value is confirmed.
public static Tuple<IEnumerable<Token>, IEnumerable<Token>, IEnumerable<Token>, IEnumerable<Token>> PartitionTokensByType(
IEnumerable<Token> tokens,
Func<string, Maybe<TypeDescriptor>> typeLookup)
{
var switchTokens = new List<Token>();
var scalarTokens = new List<Token>();
var sequenceTokens = new List<Token>();
var nonOptionTokens = new List<Token>();
var sequences = new Dictionary<Token, IList<Token>>();
var count = new Dictionary<Token, int>();
var max = new Dictionary<Token, Maybe<int>>();
var state = SequenceState.TokenSearch;
var separatorSeen = false;
Token nameToken = null;
foreach (var token in tokens)
{
if (token.IsValueForced())
{
separatorSeen = false;
nonOptionTokens.Add(token);
}
else if (token.IsName())
{
separatorSeen = false;
if (typeLookup(token.Text).MatchJust(out var info))
{
switch (info.TargetType)
{
case TargetType.Switch:
nameToken = null;
switchTokens.Add(token);
state = SequenceState.TokenSearch;
break;
case TargetType.Scalar:
nameToken = token;
// scalarTokens.Add(nameToken); <- don't add here
state = SequenceState.ScalarTokenFound;
break;
case TargetType.Sequence:
nameToken = token;
if (! sequences.ContainsKey(nameToken))
{
sequences[nameToken] = new List<Token>();
count[nameToken] = 0;
max[nameToken] = info.MaxItems;
}
state = SequenceState.SequenceTokenFound;
break;
}
}
else
{
nameToken = null;
nonOptionTokens.Add(token);
state = SequenceState.TokenSearch;
}
}
else
{
switch (state)
{
case SequenceState.TokenSearch:
case SequenceState.ScalarTokenFound when nameToken == null:
case SequenceState.SequenceTokenFound when nameToken == null:
separatorSeen = false;
nameToken = null;
nonOptionTokens.Add(token);
state = SequenceState.TokenSearch;
break;
case SequenceState.ScalarTokenFound:
separatorSeen = false;
scalarTokens.Add(nameToken); // add here instead so that scalar name token is valid only when a value is given
nameToken = null;
scalarTokens.Add(token);
state = SequenceState.TokenSearch;
break;
......
- Ngôn ngữ chính
- C#
- Star
- 4.8k
- Fork
- 478
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của commandlineparser/commandline
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
commandlineparser/commandline#951 · 1 bình luận ·
-
Code example misses iEnumerable Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
commandlineparser/commandline#880 · 2 reaction ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 45/100
commandlineparser/commandline#952 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
commandlineparser/commandline#948 ·
-
How to add examples for verbs? Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
commandlineparser/commandline#947 ·
Tất cả issue của commandlineparser/commandline
Issue tương tự
-
CS0162 "Unreachable code detected" warning from a MSBuildTemp .tmp file in every game project Đang mởbug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
Type: enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
apache/arrow-adbc#4809 ·
-
type/automation type/tech-debt
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
microsoft/vscode-azurefunctions#5197 · 1 bình luận ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
microsoft/microsoft-ui-reactor#1274 ·