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

Commit 8e9d3e8

Browse files
committed
Print a message when login is required
1 parent 7b3a47e commit 8e9d3e8

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/Program.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System.Reflection;
2323
using System.Threading.Tasks;
2424
using System.Collections.Generic;
25+
using System;
2526

2627
namespace Microsoft.Graph.Cli
2728
{
@@ -76,9 +77,17 @@ static async Task<int> Main(string[] args)
7677
var logoutCommand = new LogoutCommand(new LogoutService());
7778
commands.Add(logoutCommand.Build());
7879

79-
var builder = BuildCommandLine(client, commands);
80+
var builder = BuildCommandLine(client, commands).UseDefaults();
81+
builder.UseExceptionHandler((ex, context) => {
82+
if (ex is AuthenticationRequiredException) {
83+
Console.ResetColor();
84+
Console.ForegroundColor = ConsoleColor.Red;
85+
Console.Error.WriteLine("Token acquisition failed. Run mgc login command first to get an access token.");
86+
Console.ResetColor();
87+
}
88+
});
8089

81-
var parser = builder.UseHost(CreateHostBuilder).UseDefaults().Build();
90+
var parser = builder.UseHost(CreateHostBuilder).Build();
8291

8392
return await parser.InvokeAsync(args);
8493
}

0 commit comments

Comments
 (0)