You've already forked linux-packaging-mono
Imported Upstream version 5.12.0.220
Former-commit-id: c477e03582759447177c6d4bf412cd2355aad476
This commit is contained in:
parent
8bd104cef2
commit
8fc30896db
@@ -1390,28 +1390,27 @@ namespace Mono.Options
|
||||
o.Write (s);
|
||||
}
|
||||
|
||||
private static string GetArgumentName (int index, int maxIndex, string description)
|
||||
static string GetArgumentName (int index, int maxIndex, string description)
|
||||
{
|
||||
if (description == null)
|
||||
return maxIndex == 1 ? "VALUE" : "VALUE" + (index + 1);
|
||||
string[] nameStart;
|
||||
if (maxIndex == 1)
|
||||
nameStart = new string[]{"{0:", "{"};
|
||||
else
|
||||
nameStart = new string[]{"{" + index + ":"};
|
||||
for (int i = 0; i < nameStart.Length; ++i) {
|
||||
int start, j = 0;
|
||||
do {
|
||||
start = description.IndexOf (nameStart [i], j);
|
||||
} while (start >= 0 && j != 0 ? description [j++ - 1] == '{' : false);
|
||||
if (start == -1)
|
||||
continue;
|
||||
int end = description.IndexOf ("}", start);
|
||||
if (end == -1)
|
||||
continue;
|
||||
return description.Substring (start + nameStart [i].Length, end - start - nameStart [i].Length);
|
||||
var matches = Regex.Matches (description ?? "", @"(?<=(?<!\{)\{)[^{}]*(?=\}(?!\}))"); // ignore double braces
|
||||
string argName = "";
|
||||
foreach (Match match in matches) {
|
||||
var parts = match.Value.Split (':');
|
||||
// for maxIndex=1 it can be {foo} or {0:foo}
|
||||
if (maxIndex == 1) {
|
||||
argName = parts[parts.Length - 1];
|
||||
}
|
||||
// look for {i:foo} if maxIndex > 1
|
||||
if (maxIndex > 1 && parts.Length == 2 &&
|
||||
parts[0] == index.ToString (CultureInfo.InvariantCulture)) {
|
||||
argName = parts[1];
|
||||
}
|
||||
}
|
||||
return maxIndex == 1 ? "VALUE" : "VALUE" + (index + 1);
|
||||
|
||||
if (string.IsNullOrEmpty (argName)) {
|
||||
argName = maxIndex == 1 ? "VALUE" : "VALUE" + (index + 1);
|
||||
}
|
||||
return argName;
|
||||
}
|
||||
|
||||
private static string GetDescription (string description)
|
||||
|
@@ -413,6 +413,8 @@ namespace MonoTests.Mono.Options
|
||||
{ "color2:", "set {color}", v => {} },
|
||||
{ "rk=", "required key/value option", (k, v) => {} },
|
||||
{ "rk2=", "required {{foo}} {0:key}/{1:value} option", (k, v) => {} },
|
||||
{ "rk3=", "required {{foo}} {}", k => {} },
|
||||
{ "rk4=", "required {{foo}} {0:val}", k => {} },
|
||||
{ "ok:", "optional key/value option", (k, v) => {} },
|
||||
{ "long-desc",
|
||||
"This has a really\nlong, multi-line description that also\ntests\n" +
|
||||
@@ -456,6 +458,8 @@ namespace MonoTests.Mono.Options
|
||||
expected.WriteLine (" --color2[=color] set color");
|
||||
expected.WriteLine (" --rk=VALUE1:VALUE2 required key/value option");
|
||||
expected.WriteLine (" --rk2=key:value required {foo} key/value option");
|
||||
expected.WriteLine (" --rk3=VALUE required {foo}");
|
||||
expected.WriteLine (" --rk4=val required {foo} val");
|
||||
expected.WriteLine (" --ok[=VALUE1:VALUE2] optional key/value option");
|
||||
expected.WriteLine (" --long-desc This has a really");
|
||||
expected.WriteLine (" long, multi-line description that also");
|
||||
|
Reference in New Issue
Block a user