Skip to content

Commit b12a26d

Browse files
committed
Support -- before arguments (compat)
1 parent 2cad06e commit b12a26d

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/nbgv/Program.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static int Main(string[] args)
8686
return result;
8787
}
8888

89-
private static Command BuildCommandLine()
89+
private static Parser BuildCommandLine()
9090
{
9191
var install = new Command("install", "Prepares a project to have version stamps applied using Nerdbank.GitVersioning.")
9292
{
@@ -178,7 +178,7 @@ private static Command BuildCommandLine()
178178

179179
prepareRelease.Handler = CommandHandler.Create((string project, string nextVersion, string versionIncrement, string format, string tag) => (int)OnPrepareReleaseCommand(project, tag, nextVersion, versionIncrement, format));
180180

181-
return new RootCommand
181+
var root = new RootCommand($"{ThisAssembly.AssemblyName} {ThisAssembly.AssemblyInformationalVersion}")
182182
{
183183
install,
184184
getVersion,
@@ -188,14 +188,34 @@ private static Command BuildCommandLine()
188188
cloud,
189189
prepareRelease,
190190
};
191+
192+
var builder = new CommandLineBuilder(root);
193+
builder.UseMiddleware(context =>
194+
{
195+
// System.CommandLine 0.1 parsed arguments after optional --. Restore that behavior for compatibility.
196+
if (context.ParseResult.Errors.Count > 0 && context.ParseResult.UnparsedTokens.Count > 0)
197+
{
198+
var arguments = context.ParseResult.CommandResult.Command.Arguments;
199+
if (arguments.Count() == context.ParseResult.UnparsedTokens.Count)
200+
{
201+
context.ParseResult = context.Parser.Parse(
202+
context.ParseResult.Tokens
203+
.Where(token => token.Type != TokenType.EndOfArguments)
204+
.Select(token => token.Value)
205+
.ToArray());
206+
}
207+
}
208+
}, MiddlewareOrder.Default);
209+
210+
return builder.Build();
191211
}
192212

193213
private static int MainInner(string[] args)
194214
{
195215
try
196216
{
197-
var commandLine = BuildCommandLine();
198-
exitCode = (ExitCodes)commandLine.Invoke(args);
217+
var parser = BuildCommandLine();
218+
exitCode = (ExitCodes)parser.Invoke(args);
199219
}
200220
catch (GitException ex)
201221
{

0 commit comments

Comments
 (0)