Skip to content

Commit 1cffd0e

Browse files
lbussellmthalman
andauthored
Show help output when there are unmatched tokens passed to update-dependencies CLI (#6402)
Co-authored-by: Matt Thalman <mthalman@microsoft.com>
1 parent 1d3cad4 commit 1cffd0e

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

eng/update-dependencies/Program.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System;
45
using System.CommandLine;
6+
using System.CommandLine.Help;
57
using System.CommandLine.Hosting;
8+
using System.IO;
69
using System.Net.Http;
710
using Dotnet.Docker;
811
using Microsoft.DotNet.DarcLib;
@@ -22,8 +25,20 @@
2225
var config = new CommandLineConfiguration(rootCommand);
2326

2427
config.UseHost(
25-
_ => Host.CreateDefaultBuilder(),
26-
host => host.ConfigureServices(services =>
28+
hostBuilderFactory: unmatchedArgs =>
29+
{
30+
if (unmatchedArgs.Length > 0)
31+
{
32+
var helpBuilder = new HelpBuilder();
33+
using var stringWriter = new StringWriter();
34+
helpBuilder.Write(rootCommand, stringWriter);
35+
Console.WriteLine(stringWriter.ToString());
36+
throw new InvalidOperationException($"Unmatched tokens: {string.Join(" ", unmatchedArgs)}");
37+
}
38+
39+
return Host.CreateDefaultBuilder();
40+
},
41+
configureHost: host => host.ConfigureServices(services =>
2742
{
2843
services.AddSingleton<IBasicBarClient>(_ =>
2944
new BarApiClient(null, null, disableInteractiveAuth: true));

0 commit comments

Comments
 (0)