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

Commit bd0e3aa

Browse files
authored
Update to match CLI v1 (#42)
* Update to match CLI v1 * Update generated code
1 parent 2e4e29f commit bd0e3aa

File tree

12,575 files changed

+458654
-261245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

12,575 files changed

+458654
-261245
lines changed

.azure-pipelines/release-cli.yaml

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ stages:
7070
condition: and(succeeded(), ne('${{ parameters.simulate }}', 'true'))
7171
steps:
7272
- task: UseDotNet@2
73-
displayName: 'Use .NET 7'
73+
displayName: 'Use .NET 8'
7474
inputs:
75-
version: 7.x
75+
version: 8.x
7676

7777
# Restore NuGet packages (enables cache by default)
7878
- template: templates/nuget-packages.yaml
@@ -114,10 +114,10 @@ stages:
114114
# maxParallel: 2
115115
steps:
116116
- task: UseDotNet@2
117-
displayName: 'Use .NET 7'
117+
displayName: 'Use .NET 8'
118118
condition: and(succeeded(), ne('${{ parameters.simulate }}', 'true'))
119119
inputs:
120-
version: 7.x
120+
version: 8.x
121121

122122
- ${{ if ne(parameters.simulate, 'true') }}:
123123
- template: templates/nuget-packages.yaml
@@ -179,9 +179,9 @@ stages:
179179
condition: and(succeeded(), ne('${{ parameters.simulate }}', 'true'))
180180
steps:
181181
- task: UseDotNet@2
182-
displayName: 'Use .NET 7'
182+
displayName: 'Use .NET 8'
183183
inputs:
184-
version: 7.x
184+
version: 8.x
185185

186186
# Restore NuGet packages (enables cache by default)
187187
- template: templates/nuget-packages.yaml
@@ -410,10 +410,10 @@ stages:
410410

411411
# Nuget tool doesn't work with multi-stage builds
412412
- task: UseDotNet@2
413-
displayName: 'Use .NET 7'
414-
condition: and(succeeded(), ne('${{ parameters.simulate }}', 'true'), eq(variables['IS_NUGET'], 'true'))
413+
displayName: 'Use .NET 8'
414+
condition: and(false, succeeded(), ne('${{ parameters.simulate }}', 'true'), eq(variables['IS_NUGET'], 'true'))
415415
inputs:
416-
version: 7.x
416+
version: 8.x
417417

418418
- ${{ if ne(parameters.simulate, 'true') }}:
419419
- template: templates/nuget-packages.yaml
@@ -426,13 +426,13 @@ stages:
426426
inputs:
427427
projects: './src/msgraph-beta-cli.csproj'
428428
arguments: " --no-restore --configuration $(buildConfiguration) --no-incremental"
429-
condition: and(succeeded(), ne('${{ parameters.simulate }}', 'true'), eq(variables['IS_NUGET'], 'true'))
429+
condition: and(false, succeeded(), ne('${{ parameters.simulate }}', 'true'), eq(variables['IS_NUGET'], 'true'))
430430

431431
- pwsh: |
432432
New-Item '$(ARTIFACTS_PATH)' -ItemType Directory -Force
433433
echo "Test file" > '$(ARTIFACTS_PATH)/mgc-beta.dll'
434434
echo "Test file2" > '$(ARTIFACTS_PATH)/mgc-beta.txt'
435-
condition: and(succeeded(), eq('${{ parameters.simulate }}', 'true'), eq(variables['IS_NUGET'], 'true'))
435+
condition: and(false, succeeded(), eq('${{ parameters.simulate }}', 'true'), eq(variables['IS_NUGET'], 'true'))
436436
displayName: Simulate nuget build
437437
438438
- task: DownloadPipelineArtifact@2
@@ -448,7 +448,7 @@ stages:
448448
script: |
449449
$path = '$(ARTIFACTS_PATH)'
450450
if ('$(IS_NUGET)'.ToLower() -eq 'true' -and ('${{ parameters.simulate }}'.ToLower() -ne 'true')) {
451-
$path = './src/obj/$(buildConfiguration)/net7.0'
451+
$path = './src/obj/$(buildConfiguration)/net8.0'
452452
}
453453
Write-Verbose "Checking if $path has files"
454454
$hasArtifacts = Test-Path $path/* -PathType Leaf
@@ -489,7 +489,7 @@ stages:
489489
$destDir = '$(ARTIFACTS_PATH)-src'
490490
$sourceDir = '$(ARTIFACTS_PATH)'
491491
Expand-EsrpArtifacts -SourceDir $sourceDir -OutputDir $destDir -FileNameTemplate '$(fileNameTemplate)' -BranchOrTagName '$(branchOrTagName)' -RuntimeIdentifier '$(rid)' -PackageType $(packageType) -TarCompression $(compressionProgram) -Cleanup
492-
Move-Item -Path $destDir -Destination $sourceDir -Verbose
492+
Move-Item -Path $destDir -Destination $sourceDir
493493
494494
Move-NonExecutableItems -SourcePath $sourceDir -ExecutableItemNames mgc-beta,mgc-beta.exe
495495
verbosePreference: '$(OUTPUT_PREFERENCE)'
@@ -514,12 +514,12 @@ stages:
514514
- pwsh: |
515515
Write-Host "##vso[task.setvariable variable=ESRP_FILE_PATTERN]$(pattern)"
516516
displayName: Compute ESRP filter pattern Windows/Nuget
517-
condition: and(succeeded(), eq(variables['SHOULD_SIGN'], 'True'), or(startsWith(variables['RUNTIME_ID'], 'win'), eq(variables['IS_NUGET'], 'true')))
517+
condition: and(false, succeeded(), eq(variables['SHOULD_SIGN'], 'True'), or(startsWith(variables['RUNTIME_ID'], 'win'), eq(variables['IS_NUGET'], 'true')))
518518
519519
# ESRP needs .NET 6
520520
- task: UseDotNet@2
521521
displayName: 'Change to .NET 6'
522-
condition: and(succeeded(), ne('${{ parameters.simulate }}', 'true'), eq(variables['IS_NUGET'], 'true'))
522+
condition: and(false, succeeded(), ne('${{ parameters.simulate }}', 'true'), eq(variables['IS_NUGET'], 'true'))
523523
inputs:
524524
version: 6.x
525525

@@ -553,7 +553,7 @@ stages:
553553
dotnet pack ./src/msgraph-beta-cli.csproj --configuration $(buildConfiguration) --output $(SIGN_PATH) --no-build --include-symbols --include-source /p:SymbolPackageFormat=snupkg -v d
554554
workingDirectory: $(Build.SourcesDirectory)
555555
displayName: DotNet pack (nuget)
556-
condition: and(succeeded(), eq(variables['SHOULD_SIGN'], 'True'), ne('${{ parameters.simulate }}', 'true'), eq(variables['Is_NUGET'], 'true'))
556+
condition: and(false, succeeded(), eq(variables['SHOULD_SIGN'], 'True'), ne('${{ parameters.simulate }}', 'true'), eq(variables['IS_NUGET'], 'true'))
557557
558558
- task: EsrpCodeSigning@2
559559
displayName: 'ESRP CodeSigning (Sign Nuget)'
@@ -566,12 +566,12 @@ stages:
566566
Pattern: "*.nupkg"
567567
inlineOperation: $(inlineNugetSignOperation)
568568
SessionTimeout: 20
569-
condition: and(succeeded(), ne('${{ parameters.simulate }}', 'true'), eq(variables['SHOULD_SIGN'], 'True'), eq(variables['IS_NUGET'], 'true'))
569+
condition: and(false, succeeded(), ne('${{ parameters.simulate }}', 'true'), eq(variables['SHOULD_SIGN'], 'True'), eq(variables['IS_NUGET'], 'true'))
570570

571571
- pwsh: |
572572
$artifactsPath = '$(SIGN_PATH)'
573573
Write-Host "##vso[task.setvariable variable=WORKING_DIR]$artifactsPath"
574-
condition: and(succeeded(), eq(variables['SHOULD_SIGN'], 'True'), eq(variables['IS_NUGET'], 'true'))
574+
condition: and(false, succeeded(), eq(variables['SHOULD_SIGN'], 'True'), eq(variables['IS_NUGET'], 'true'))
575575
576576
- task: PowerShell@2
577577
displayName: Simulate ESRP
@@ -691,7 +691,9 @@ stages:
691691
displayName: Deploy Nuget
692692
dependsOn: []
693693
environment: microsoftgraph-nuget-org
694-
condition: and(succeeded(), or(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'), eq('${{ parameters.forceNugetPublish }}', 'true')))
694+
# Disable nuget deployment until performance is improved.
695+
condition: false
696+
# condition: and(succeeded(), or(startsWith(variables['Build.SourceBranch'], 'refs/tags/v'), eq('${{ parameters.forceNugetPublish }}', 'true')))
695697
strategy:
696698
runOnce:
697699
deploy:

.azure-pipelines/templates/prepare-unsigned-executable-darwin.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ parameters:
2323
steps:
2424
- pwsh: |
2525
Write-Host "##vso[task.setvariable variable=IS_ENABLED]${{ parameters.enabled }}"
26-
displayName: Check prepare-unsigned-executable-darwin.yaml enabled
26+
displayName: Check enabled
2727
condition: and(succeeded(), eq(variables['SHOULD_SIGN'], 'True'))
2828
2929
- pwsh: |

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# 2. Use the \\?\ prefix when specifying the path in the docker build command. e.g.
44
# docker build \\?\C:\path -f .\Dockerfile
55
# See https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
6-
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build-env
6+
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build-env
77

88
ARG MSGRAPH_NUGET_URL=https://nuget.pkg.github.com/microsoftgraph/index.json
99

@@ -16,7 +16,7 @@ WORKDIR /app/msgraph-beta-cli
1616

1717
RUN dotnet publish -p:PublishSingleFile=false -p:PublishReadyToRun=true -p:PublishReadyToRunShowWarnings=true ./src/msgraph-beta-cli.csproj --configuration Release --no-self-contained --runtime linux-musl-x64 --output /app/output
1818

19-
FROM mcr.microsoft.com/dotnet/runtime:7.0-alpine as runtime
19+
FROM mcr.microsoft.com/dotnet/runtime:8.0-alpine as runtime
2020

2121
# Change this password by providing a different value when running the container
2222
ENV KEYRING_PASSWORD="password"

src/Program.cs

Lines changed: 88 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
using Microsoft.Kiota.Abstractions;
2929
using Microsoft.Kiota.Abstractions.Authentication;
3030
using Microsoft.Kiota.Cli.Commons.Extensions;
31+
using Microsoft.Kiota.Cli.Commons.Http;
32+
using Microsoft.Kiota.Cli.Commons.Http.Headers;
3133
using Microsoft.Kiota.Http.HttpClientLibrary;
3234
using Microsoft.Kiota.Serialization.Form;
3335
using Microsoft.Kiota.Serialization.Json;
@@ -42,10 +44,51 @@ class Program
4244

4345
static async Task<int> Main(string[] args)
4446
{
45-
Console.InputEncoding = Encoding.Unicode;
46-
Console.OutputEncoding = Encoding.Unicode;
47+
Console.InputEncoding = Encoding.UTF8;
48+
Console.OutputEncoding = Encoding.UTF8;
49+
// Replace `me ...` with `users ... --user-id me`
50+
if (args.Length > 0 && args[0] == "me")
51+
{
52+
var hasHelp = Array.Exists(args, static x => x == "--help" || x == "-h" || x == "/?");
53+
var newArgs = hasHelp ? args : new string[args.Length + 2];
54+
newArgs[0] = "users";
55+
for (var i = 1; i < args.Length; i++)
56+
{
57+
newArgs[i] = args[i];
58+
}
59+
if (newArgs.Length > args.Length)
60+
{
61+
newArgs[args.Length] = "--user-id";
62+
newArgs[args.Length + 1] = "me";
63+
args = newArgs;
64+
}
65+
}
66+
4767
var builder = BuildCommandLine()
48-
.UseDefaults()
68+
.UseVersionOption()
69+
.UseHelp()
70+
.UseEnvironmentVariableDirective()
71+
.UseParseDirective()
72+
.UseSuggestDirective()
73+
.RegisterWithDotnetSuggest()
74+
.UseTypoCorrections()
75+
.UseParseErrorReporting()
76+
.CancelOnProcessTermination()
77+
.UseExceptionHandler((ex, context) =>
78+
{
79+
var message = GetExceptionMessage(ex);
80+
var exitCode = GetExceptionExitCode(ex);
81+
82+
if (!string.IsNullOrEmpty(message))
83+
{
84+
Console.ResetColor();
85+
Console.ForegroundColor = ConsoleColor.Red;
86+
context.Console.Error.WriteLine(message);
87+
Console.ResetColor();
88+
}
89+
90+
context.ExitCode = exitCode;
91+
})
4992
.UseHost(CreateHostBuilder)
5093
.UseRequestAdapter(ic =>
5194
{
@@ -58,7 +101,9 @@ static async Task<int> Main(string[] args)
58101
}
59102
adapter.BaseUrl = adapter.BaseUrl?.TrimEnd('/');
60103
return adapter;
61-
}).RegisterCommonServices();
104+
})
105+
.RegisterCommonServices()
106+
.RegisterHeadersOption(() => InMemoryHeadersStore.Instance);
62107
builder.AddMiddleware(async (ic, next) =>
63108
{
64109
var host = ic.GetHost();
@@ -69,46 +114,38 @@ static async Task<int> Main(string[] args)
69114
ic.BindingContext.AddService(_ => host.Services.GetRequiredService<LogoutService>());
70115
await next(ic);
71116
});
72-
builder.UseExceptionHandler((ex, context) =>
117+
118+
try
119+
{
120+
var parser = builder.Build();
121+
return await parser.InvokeAsync(args);
122+
}
123+
finally
73124
{
74-
var message = ex switch
125+
listener?.Dispose();
126+
}
127+
}
128+
129+
static string? GetExceptionMessage<E>(E ex) where E: Exception {
130+
return ex switch
75131
{
76132
_ when ex is AuthenticationRequiredException => "Token acquisition failed. Run mgc-beta login command first to get an access token.",
77133
_ when ex is TaskCanceledException => string.Empty,
78134
ODataError _e when ex is ODataError => $"Error {_e.ResponseStatusCode}({_e.Error?.Code}) from API:\n {_e.Error?.Message}",
79135
ApiException _e when ex is ApiException => $"Error {_e.ResponseStatusCode} from API.",
136+
AuthenticationFailedException e => $"Authentication failed: {e.Message}",
137+
Identity.Client.MsalException e => $"Authentication failed: {e.Message}",
80138
_ => ex.Message
81139
};
140+
}
82141

83-
var exitCode = ex switch
142+
static int GetExceptionExitCode<E>(E ex) where E: Exception => ex switch
84143
{
85144
_ when ex is AuthenticationRequiredException => 1,
86145
_ when ex is TaskCanceledException => 0,
87146
_ => -1
88147
};
89148

90-
if (!string.IsNullOrEmpty(message))
91-
{
92-
Console.ResetColor();
93-
Console.ForegroundColor = ConsoleColor.Red;
94-
context.Console.Error.WriteLine(message);
95-
Console.ResetColor();
96-
}
97-
98-
context.ExitCode = exitCode;
99-
});
100-
101-
try
102-
{
103-
var parser = builder.Build();
104-
return await parser.InvokeAsync(args);
105-
}
106-
finally
107-
{
108-
listener?.Dispose();
109-
}
110-
}
111-
112149
static CommandLineBuilder BuildCommandLine()
113150
{
114151
var rootCommand = new GraphClient().BuildRootCommand();
@@ -120,7 +157,14 @@ static CommandLineBuilder BuildCommandLine()
120157
builder.AddMiddleware(async (ic, next) =>
121158
{
122159
debugEnabled = ic.ParseResult.GetValueForOption<bool>(debugOption);
123-
listener = AzureEventSourceListener.CreateConsoleLogger(debugEnabled ? EventLevel.LogAlways : EventLevel.Warning);
160+
if (debugEnabled)
161+
{
162+
listener = CreateStdErrLogger(EventLevel.LogAlways);
163+
}
164+
else
165+
{
166+
listener = CreateStdErrLogger(EventLevel.Error);
167+
}
124168
await next(ic);
125169
});
126170

@@ -152,7 +196,8 @@ static IHostBuilder CreateHostBuilder(string[] args) =>
152196
GraphServiceLibraryClientVersion = $"{assemblyVersion?.Major ?? 0}.{assemblyVersion?.Minor ?? 0}.{assemblyVersion?.Build ?? 0}",
153197
GraphServiceTargetVersion = "beta"
154198
};
155-
return GraphCliClientFactory.GetDefaultClient(options, version: "beta", loggingHandler: p.GetRequiredService<LoggingHandler>());
199+
var headersHandler = new NativeHttpHeadersHandler(() => InMemoryHeadersStore.Instance, p.GetService<ILogger<NativeHttpHeadersHandler>>());
200+
return GraphCliClientFactory.GetDefaultClient(options, version: options.GraphServiceTargetVersion, loggingHandler: p.GetRequiredService<LoggingHandler>(), middlewares: new[] { headersHandler });
156201
});
157202
services.AddSingleton<IAuthenticationProvider>(p =>
158203
{
@@ -193,6 +238,9 @@ static IHostBuilder CreateHostBuilder(string[] args) =>
193238
}).ConfigureLogging((ctx, logBuilder) =>
194239
{
195240
logBuilder.SetMinimumLevel(LogLevel.Warning);
241+
logBuilder.ClearProviders();
242+
// Log everything to stderr.
243+
logBuilder.AddConsole(c => c.LogToStandardErrorThreshold = LogLevel.Trace);
196244
// Allow runtime selection of log level
197245
logBuilder.AddFilter("Microsoft.Graph.Cli", level => level >= (debugEnabled ? LogLevel.Debug : LogLevel.Warning));
198246
});
@@ -209,5 +257,14 @@ static void ConfigureAppConfiguration(IConfigurationBuilder builder, string[] ar
209257
builder.AddJsonFile(authCache.GetAuthenticationCacheFilePath(), optional: true, reloadOnChange: true);
210258
builder.AddEnvironmentVariables(prefix: "MGC_");
211259
}
260+
261+
static AzureEventSourceListener CreateStdErrLogger(EventLevel level = EventLevel.Informational)
262+
{
263+
return new AzureEventSourceListener(delegate (EventWrittenEventArgs eventData, string text)
264+
{
265+
// By default, AzureEventSourceListener.CreateConsoleLogger logs to stdout. Use stderr instead.
266+
Console.Error.WriteLine("[{1}] {0}: {2}", eventData.EventSource.Name, eventData.Level, text);
267+
}, level);
268+
}
212269
}
213270
}

0 commit comments

Comments
 (0)