Skip to content

Commit

Permalink
- adds display url to the CLI experience
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Biret <[email protected]>
  • Loading branch information
baywet committed May 14, 2024
1 parent dd7c9ad commit b6bd747
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added support for multipart form data request body in PHP. [#3029](https://github.com/microsoft/kiota/issues/3029)
- Added uri-form encoded serialization for PHP. [#2074](https://github.com/microsoft/kiota/issues/2074)
- Added information message with base URL in the CLI experience. [#4635](https://github.com/microsoft/kiota/issues/4635)

### Changed

Expand Down
3 changes: 3 additions & 0 deletions src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,10 @@ internal void FilterPathsByPatterns(OpenApiDocument doc)
internal void SetApiRootUrl()
{
if (openApiDocument is not null && openApiDocument.GetAPIRootUrl(config.OpenAPIFilePath) is string candidateUrl)
{
config.ApiRootUrl = candidateUrl;
logger.LogInformation("Client root URL set to {ApiRootUrl}", candidateUrl);
}
else
logger.LogWarning("No server url found in the OpenAPI document. The base url will need to be set when using the client.");
}
Expand Down
5 changes: 5 additions & 0 deletions src/kiota/Handlers/BaseKiotaCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ private static string GetSourceArg(string path, string manifest)
{
return string.IsNullOrEmpty(manifest) ? $"-d \"{path}\"" : $"-a \"{manifest}\"";
}
protected void DisplayUrlInformation(string? apiRootUrl, bool isPlugin = false)
{
if (!string.IsNullOrEmpty(apiRootUrl))
DisplayInfo($"{(isPlugin ? "Plugin" : "Client")} base url set to {apiRootUrl}");
}
protected void DisplayGenerateCommandHint()
{
DisplayHint("Hint: use the client generate command to generate the code.",
Expand Down
3 changes: 3 additions & 0 deletions src/kiota/Handlers/Client/AddHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ public override async Task<int> InvokeAsync(InvocationContext context)
var builder = new KiotaBuilder(logger, Configuration.Generation, httpClient, true);
var result = await builder.GenerateClientAsync(cancellationToken).ConfigureAwait(false);
if (result)
{
DisplaySuccess("Generation completed successfully");
DisplayUrlInformation(Configuration.Generation.ApiRootUrl);
}
else if (skipGeneration)
{
DisplaySuccess("Generation skipped as --skip-generation was passed");
Expand Down
3 changes: 3 additions & 0 deletions src/kiota/Handlers/Client/EditHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ public override async Task<int> InvokeAsync(InvocationContext context)
var builder = new KiotaBuilder(logger, Configuration.Generation, httpClient, true);
var result = await builder.GenerateClientAsync(cancellationToken).ConfigureAwait(false);
if (result)
{
DisplaySuccess("Generation completed successfully");
DisplayUrlInformation(Configuration.Generation.ApiRootUrl);
}
else if (skipGeneration)
{
DisplaySuccess("Generation skipped as --skip-generation was passed");
Expand Down
1 change: 1 addition & 0 deletions src/kiota/Handlers/Client/GenerateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public override async Task<int> InvokeAsync(InvocationContext context)
if (result)
{
DisplaySuccess($"Update of {clientEntry.Key} client completed");
DisplayUrlInformation(generationConfiguration.ApiRootUrl);
var manifestPath = $"{GetAbsolutePath(Path.Combine(WorkspaceConfigurationStorageService.KiotaDirectorySegment, WorkspaceConfigurationStorageService.ManifestFileName))}#{clientEntry.Key}";
DisplayInfoHint(generationConfiguration.Language, string.Empty, manifestPath);
}
Expand Down
3 changes: 3 additions & 0 deletions src/kiota/Handlers/KiotaGenerateCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ public override async Task<int> InvokeAsync(InvocationContext context)
var builder = new KiotaBuilder(logger, Configuration.Generation, httpClient);
var result = await builder.GenerateClientAsync(cancellationToken).ConfigureAwait(false);
if (result)
{
DisplaySuccess("Generation completed successfully");
DisplayUrlInformation(Configuration.Generation.ApiRootUrl);
}
else
{
DisplaySuccess("Generation skipped as no changes were detected");
Expand Down
3 changes: 3 additions & 0 deletions src/kiota/Handlers/KiotaUpdateCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ public override async Task<int> InvokeAsync(InvocationContext context)
var results = await Task.WhenAll(configurations
.Select(x => GenerateClientAsync(context, x, cancellationToken)));
foreach (var (lockInfo, lockDirectoryPath) in locks)
{
DisplaySuccess($"Update of {lockInfo?.ClientClassName} client for {lockInfo?.Language} at {lockDirectoryPath} completed");
DisplayUrlInformation(configurations.FirstOrDefault(x => lockDirectoryPath.Equals(x.OutputPath, StringComparison.OrdinalIgnoreCase))?.ApiRootUrl);
}
DisplaySuccess($"Update of {locks.Length} clients completed successfully");
foreach (var configuration in configurations)
DisplayInfoHint(configuration.Language, configuration.OpenAPIFilePath, string.Empty);
Expand Down
3 changes: 3 additions & 0 deletions src/kiota/Handlers/Plugin/AddHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ public override async Task<int> InvokeAsync(InvocationContext context)
var builder = new KiotaBuilder(logger, Configuration.Generation, httpClient, true);
var result = await builder.GeneratePluginAsync(cancellationToken).ConfigureAwait(false);
if (result)
{
DisplaySuccess("Generation completed successfully");
DisplayUrlInformation(Configuration.Generation.ApiRootUrl);
}
else if (skipGeneration)
{
DisplaySuccess("Generation skipped as --skip-generation was passed");
Expand Down
3 changes: 3 additions & 0 deletions src/kiota/Handlers/Plugin/EditHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ public override async Task<int> InvokeAsync(InvocationContext context)
var builder = new KiotaBuilder(logger, Configuration.Generation, httpClient, true);
var result = await builder.GeneratePluginAsync(cancellationToken).ConfigureAwait(false);
if (result)
{
DisplaySuccess("Generation completed successfully");
DisplayUrlInformation(Configuration.Generation.ApiRootUrl);
}
else if (skipGeneration)
{
DisplaySuccess("Generation skipped as --skip-generation was passed");
Expand Down

0 comments on commit b6bd747

Please sign in to comment.