Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit f5a12c8

Browse files
committed
Add output filter resolution
1 parent 47940be commit f5a12c8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Program.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using System.Threading.Tasks;
2626
using System.Collections.Generic;
2727
using System;
28+
using System.CommandLine.IO;
2829

2930
namespace Microsoft.Graph.Cli
3031
{
@@ -80,14 +81,22 @@ static async Task<int> Main(string[] args)
8081
var builder = BuildCommandLine(client, commands).UseDefaults().UseHost(CreateHostBuilder);
8182
builder.AddMiddleware((invocation) => {
8283
var host = invocation.GetHost();
84+
var outputFilter = host.Services.GetRequiredService<IOutputFilter>();
8385
var outputFormatterFactory = host.Services.GetRequiredService<IOutputFormatterFactory>();
86+
invocation.BindingContext.AddService<IOutputFilter>(_ => outputFilter);
8487
invocation.BindingContext.AddService<IOutputFormatterFactory>(_ => outputFormatterFactory);
8588
});
8689
builder.UseExceptionHandler((ex, context) => {
8790
if (ex is AuthenticationRequiredException) {
8891
Console.ResetColor();
8992
Console.ForegroundColor = ConsoleColor.Red;
90-
Console.Error.WriteLine("Token acquisition failed. Run mgc login command first to get an access token.");
93+
context.Console.Error.WriteLine("Token acquisition failed. Run mgc login command first to get an access token.");
94+
Console.ResetColor();
95+
} else {
96+
Console.ResetColor();
97+
Console.ForegroundColor = ConsoleColor.Red;
98+
context.Console.Error.WriteLine(ex.Message);
99+
context.Console.Error.WriteLine(ex.StackTrace);
91100
Console.ResetColor();
92101
}
93102
});
@@ -118,6 +127,7 @@ static IHostBuilder CreateHostBuilder(string[] args) =>
118127
var authSection = ctx.Configuration.GetSection(Constants.AuthenticationSection);
119128
services.Configure<AuthenticationOptions>(authSection);
120129
services.AddSingleton<IPathUtility, PathUtility>();
130+
services.AddSingleton<IOutputFilter, JmesPathOutputFilter>();
121131
services.AddSingleton<IOutputFormatterFactory, OutputFormatterFactory>();
122132
});
123133

0 commit comments

Comments
 (0)