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

Commit 5cc3214

Browse files
committed
Update system.commandline library
1 parent 8ef50d0 commit 5cc3214

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

src/Commands/Authentication/LoginCommand.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ public LoginCommand(AuthenticationServiceFactory authenticationServiceFactory) {
1919

2020
public Command Build() {
2121
var loginCommand = new Command("login", "Login and store the session for use in subsequent commands");
22-
var scopes = new Option<string>("--scopes", "The login scopes e.g. User.Read");
22+
var scopes = new Option<string>("--scopes", "The login scopes e.g. User.Read") {
23+
Arity = ArgumentArity.OneOrMore
24+
};
2325
scopes.IsRequired = true;
24-
scopes.Arity = ArgumentArity.OneOrMore;
2526
loginCommand.AddOption(scopes);
2627

2728
var strategy = new Option<AuthenticationStrategy>("--strategy", () => Constants.defaultAuthStrategy, "The authentication strategy to use.");
2829
loginCommand.AddOption(strategy);
29-
30-
loginCommand.Handler = CommandHandler.Create<string[], AuthenticationStrategy, IHost>(async (scopes, strategy, host) =>
30+
loginCommand.SetHandler<string[], AuthenticationStrategy, IHost>(async (scopes, strategy, host) =>
3131
{
3232
var options = host.Services.GetRequiredService<IOptionsMonitor<AuthenticationOptions>>().CurrentValue;
3333
var authService = await this.authenticationServiceFactory.GetAuthenticationServiceAsync(strategy, options?.TenantId, options?.ClientId);
3434
await authService.LoginAsync(scopes);
35-
});
35+
}, scopes, strategy);
3636

3737
return loginCommand;
3838
}

src/Commands/Authentication/LogoutCommand.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ public LogoutCommand(LogoutService logoutService) {
1515

1616
public Command Build() {
1717
var logoutCommand = new Command("logout", "Logout by deleting the stored session used in commands");
18-
19-
logoutCommand.Handler = CommandHandler.Create(() =>
18+
logoutCommand.SetHandler(() =>
2019
{
2120
this.logoutService.Logout();
2221
});

src/Program.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using System.Net.Http;
2222
using System.Reflection;
2323
using System.Threading.Tasks;
24+
using System.Collections.Generic;
2425

2526
namespace Microsoft.Graph.Cli
2627
{
@@ -65,24 +66,32 @@ static async Task<int> Main(string[] args)
6566
using var httpClient = KiotaClientFactory.Create(finalHandler);
6667
var core = new HttpClientRequestAdapter(authProvider, httpClient: httpClient);
6768
var client = new GraphClient(core);
68-
var builder = BuildCommandLine(client);
69+
var rootCommand = client.BuildCommand();
70+
rootCommand.Description = "Microsoft Graph CLI";
6971

72+
var commands = new List<Command>();
7073
var loginCommand = new LoginCommand(authServiceFactory);
71-
builder.AddCommand(loginCommand.Build());
74+
commands.Add(loginCommand.Build());
7275

7376
var logoutCommand = new LogoutCommand(new LogoutService());
74-
builder.AddCommand(logoutCommand.Build());
77+
commands.Add(logoutCommand.Build());
78+
79+
var builder = BuildCommandLine(client, commands);
7580

7681
var parser = builder.UseHost(CreateHostBuilder).UseDefaults().Build();
7782

7883
return await parser.InvokeAsync(args);
7984
}
8085

81-
static CommandLineBuilder BuildCommandLine(GraphClient client)
86+
static CommandLineBuilder BuildCommandLine(GraphClient client, IEnumerable<Command> commands)
8287
{
8388
var rootCommand = client.BuildCommand();
8489
rootCommand.Description = "Microsoft Graph CLI";
8590

91+
foreach (var command in commands) {
92+
rootCommand.AddCommand(command);
93+
}
94+
8695
return new CommandLineBuilder(rootCommand);
8796
}
8897

src/msgraph-cli.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
2626
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
2727
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
28-
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.0.25" />
28+
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.0.26" />
2929
<PackageReference Include="Microsoft.Kiota.Authentication.Azure" Version="1.0.6" />
3030
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.0.16" />
3131
<PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.0.6" />
32-
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21308.1" />
33-
<PackageReference Include="System.CommandLine.Hosting" Version="0.3.0-alpha.21216.1" />
32+
<PackageReference Include="System.CommandLine" Version="2.0.0-beta2.21617.1" />
33+
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.21617.1" />
3434
</ItemGroup>
3535

3636
<ItemGroup>

0 commit comments

Comments
 (0)