|
|
|
@ -1,6 +1,7 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
|
|
|
|
namespace Volo.Abp.Cli.Args |
|
|
|
@ -71,6 +72,11 @@ namespace Volo.Abp.Cli.Args |
|
|
|
return commandLineArgs; |
|
|
|
} |
|
|
|
|
|
|
|
public CommandLineArgs Parse(string lineText) |
|
|
|
{ |
|
|
|
return Parse(GetArgsArrayFromLine(lineText)); |
|
|
|
} |
|
|
|
|
|
|
|
private static bool IsOptionName(string argument) |
|
|
|
{ |
|
|
|
return argument.StartsWith("-") || argument.StartsWith("--"); |
|
|
|
@ -100,5 +106,46 @@ namespace Volo.Abp.Cli.Args |
|
|
|
|
|
|
|
throw new ArgumentException("Option names should start with '-' or '--'."); |
|
|
|
} |
|
|
|
|
|
|
|
private static string[] GetArgsArrayFromLine(string lineText) |
|
|
|
{ |
|
|
|
var args = new List<string>(); |
|
|
|
var currentArgBuilder = new StringBuilder(); |
|
|
|
string currentArg = null; |
|
|
|
bool isInQuotes = false; |
|
|
|
for (int i = 0; i < lineText.Length; i++) |
|
|
|
{ |
|
|
|
var c = lineText[i]; |
|
|
|
if (c == ' ' && !isInQuotes) |
|
|
|
{ |
|
|
|
currentArg = currentArgBuilder.ToString(); |
|
|
|
if (!currentArg.IsNullOrWhiteSpace()) |
|
|
|
{ |
|
|
|
args.Add(currentArg); |
|
|
|
} |
|
|
|
|
|
|
|
currentArgBuilder = new StringBuilder(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (c == '\"') |
|
|
|
{ |
|
|
|
isInQuotes = !isInQuotes; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
currentArgBuilder.Append(c); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
currentArg = currentArgBuilder.ToString(); |
|
|
|
if (!currentArg.IsNullOrWhiteSpace()) |
|
|
|
{ |
|
|
|
args.Add(currentArg); |
|
|
|
} |
|
|
|
|
|
|
|
return args.ToArray(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |