-
Notifications
You must be signed in to change notification settings - Fork 292
adds kiota client edit command #4294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
15895ad
- code linting
baywet e0f3635
- code linting
baywet 869c862
- draft implementation of the edit command
baywet 425b9b6
- code linting
baywet b48192d
- fixes defaults for edit command
baywet b8b2d3b
- code cleanup
baywet 0053504
- adds success message on edit generation change
baywet cd2fd86
- adds launch configurations for new commands
baywet 7c97dc9
- fixes missing serializers/deserializers on client update/edit
baywet 4c69e6d
- cleans up leave open workaround
baywet 0209e79
- adds client directory removal
baywet ecd8d0b
- adds confirmation message after removing the client
baywet 92e22bf
- updates changelog for one twelve release
baywet 2c9bea1
Merge pull request #4299 from microsoft/release/onetwelvezero
baywet 3fe6765
Update src/kiota/Handlers/BaseKiotaCommandHandler.cs
baywet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.CommandLine; | ||
| using System.CommandLine.Invocation; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Text.Json; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Kiota.Builder; | ||
| using Kiota.Builder.Configuration; | ||
| using Kiota.Builder.Extensions; | ||
| using Kiota.Builder.WorkspaceManagement; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace kiota.Handlers.Client; | ||
|
|
||
| internal class EditHandler : BaseKiotaCommandHandler | ||
| { | ||
| public required Option<string> ClassOption | ||
| { | ||
| get; init; | ||
| } | ||
| public required Option<bool?> BackingStoreOption | ||
| { | ||
| get; init; | ||
| } | ||
| public required Option<string> OutputOption | ||
| { | ||
| get; init; | ||
| } | ||
| public required Option<GenerationLanguage?> LanguageOption | ||
| { | ||
| get; init; | ||
| } | ||
| public required Option<string> DescriptionOption | ||
| { | ||
| get; init; | ||
| } | ||
| public required Option<string> NamespaceOption | ||
| { | ||
| get; init; | ||
| } | ||
| public required Option<bool?> AdditionalDataOption | ||
| { | ||
| get; init; | ||
| } | ||
| public required Option<List<string>> DisabledValidationRulesOption | ||
| { | ||
| get; init; | ||
| } | ||
| public required Option<List<string>> StructuredMimeTypesOption | ||
| { | ||
| get; init; | ||
| } | ||
| public required Option<bool?> ExcludeBackwardCompatibleOption | ||
| { | ||
| get; | ||
| set; | ||
| } | ||
| public required Option<List<string>> IncludePatternsOption | ||
| { | ||
| get; init; | ||
| } | ||
| public required Option<List<string>> ExcludePatternsOption | ||
| { | ||
| get; init; | ||
| } | ||
| public required Option<bool> SkipGenerationOption | ||
| { | ||
| get; init; | ||
| } | ||
|
|
||
| public override async Task<int> InvokeAsync(InvocationContext context) | ||
| { | ||
| string output = context.ParseResult.GetValueForOption(OutputOption) ?? string.Empty; | ||
| GenerationLanguage? language = context.ParseResult.GetValueForOption(LanguageOption); | ||
| string openapi = context.ParseResult.GetValueForOption(DescriptionOption) ?? string.Empty; | ||
| bool? backingStore = context.ParseResult.GetValueForOption(BackingStoreOption); | ||
| bool? excludeBackwardCompatible = context.ParseResult.GetValueForOption(ExcludeBackwardCompatibleOption); | ||
| bool? includeAdditionalData = context.ParseResult.GetValueForOption(AdditionalDataOption); | ||
| bool skipGeneration = context.ParseResult.GetValueForOption(SkipGenerationOption); | ||
| string className = context.ParseResult.GetValueForOption(ClassOption) ?? string.Empty; | ||
| string namespaceName = context.ParseResult.GetValueForOption(NamespaceOption) ?? string.Empty; | ||
| List<string>? includePatterns = context.ParseResult.GetValueForOption(IncludePatternsOption); | ||
| List<string>? excludePatterns = context.ParseResult.GetValueForOption(ExcludePatternsOption); | ||
| List<string>? disabledValidationRules = context.ParseResult.GetValueForOption(DisabledValidationRulesOption); | ||
| List<string>? structuredMimeTypes = context.ParseResult.GetValueForOption(StructuredMimeTypesOption); | ||
| CancellationToken cancellationToken = context.BindingContext.GetService(typeof(CancellationToken)) is CancellationToken token ? token : CancellationToken.None; | ||
|
|
||
| Configuration.Generation.SkipGeneration = skipGeneration; | ||
| Configuration.Generation.Operation = ClientOperation.Edit; | ||
|
|
||
| var (loggerFactory, logger) = GetLoggerAndFactory<KiotaBuilder>(context, Configuration.Generation.OutputPath); | ||
| using (loggerFactory) | ||
| { | ||
| await CheckForNewVersionAsync(logger, cancellationToken).ConfigureAwait(false); | ||
| logger.AppendInternalTracing(); | ||
| logger.LogTrace("configuration: {configuration}", JsonSerializer.Serialize(Configuration, KiotaConfigurationJsonContext.Default.KiotaConfiguration)); | ||
|
|
||
| try | ||
| { | ||
| var workspaceStorageService = new WorkspaceConfigurationStorageService(Directory.GetCurrentDirectory()); | ||
| var (config, _) = await workspaceStorageService.GetWorkspaceConfigurationAsync(cancellationToken).ConfigureAwait(false); | ||
| if (config == null) | ||
| { | ||
| DisplayError("The workspace configuration is missing, please run the init command first."); | ||
| return 1; | ||
| } | ||
| if (!config.Clients.TryGetValue(className, out var clientConfiguration)) | ||
| { | ||
| DisplayError($"No client found with the provided name {className}"); | ||
| return 1; | ||
| } | ||
| clientConfiguration.UpdateGenerationConfigurationFromApiClientConfiguration(Configuration.Generation, className); | ||
| if (language.HasValue) | ||
| Configuration.Generation.Language = language.Value; | ||
| if (backingStore.HasValue) | ||
| Configuration.Generation.UsesBackingStore = backingStore.Value; | ||
| if (excludeBackwardCompatible.HasValue) | ||
| Configuration.Generation.ExcludeBackwardCompatible = excludeBackwardCompatible.Value; | ||
| if (includeAdditionalData.HasValue) | ||
| Configuration.Generation.IncludeAdditionalData = includeAdditionalData.Value; | ||
| AssignIfNotNullOrEmpty(output, (c, s) => c.OutputPath = s); | ||
| AssignIfNotNullOrEmpty(openapi, (c, s) => c.OpenAPIFilePath = s); | ||
| AssignIfNotNullOrEmpty(className, (c, s) => c.ClientClassName = s); | ||
| AssignIfNotNullOrEmpty(namespaceName, (c, s) => c.ClientNamespaceName = s); | ||
| if (includePatterns is { Count: > 0 }) | ||
| Configuration.Generation.IncludePatterns = includePatterns.Select(static x => x.TrimQuotes()).ToHashSet(StringComparer.OrdinalIgnoreCase); | ||
| if (excludePatterns is { Count: > 0 }) | ||
| Configuration.Generation.ExcludePatterns = excludePatterns.Select(static x => x.TrimQuotes()).ToHashSet(StringComparer.OrdinalIgnoreCase); | ||
| if (disabledValidationRules is { Count: > 0 }) | ||
| Configuration.Generation.DisabledValidationRules = disabledValidationRules | ||
| .Select(static x => x.TrimQuotes()) | ||
| .SelectMany(static x => x.Split(',', StringSplitOptions.RemoveEmptyEntries)) | ||
| .ToHashSet(StringComparer.OrdinalIgnoreCase); | ||
| if (structuredMimeTypes is { Count: > 0 }) | ||
| Configuration.Generation.StructuredMimeTypes = new(structuredMimeTypes.SelectMany(static x => x.Split(' ', StringSplitOptions.RemoveEmptyEntries)) | ||
| .Select(static x => x.TrimQuotes())); | ||
|
|
||
| DefaultSerializersAndDeserializers(Configuration.Generation); | ||
| var builder = new KiotaBuilder(logger, Configuration.Generation, httpClient, true); | ||
| var result = await builder.GenerateClientAsync(cancellationToken).ConfigureAwait(false); | ||
| if (result) | ||
| DisplaySuccess("Generation completed successfully"); | ||
| else if (skipGeneration) | ||
| { | ||
| DisplaySuccess("Generation skipped as --skip-generation was passed"); | ||
| DisplayGenerateCommandHint(); | ||
| } | ||
| else | ||
| { | ||
| DisplayWarning("Generation skipped as no changes were detected"); | ||
| DisplayCleanHint("client generate", "--refresh"); | ||
| } | ||
| var manifestPath = $"{GetAbsolutePath(WorkspaceConfigurationStorageService.ManifestFileName)}#{Configuration.Generation.ClientClassName}"; | ||
| DisplayInfoHint(Configuration.Generation.Language, string.Empty, manifestPath); | ||
| DisplayGenerateAdvancedHint(includePatterns ?? [], excludePatterns ?? [], string.Empty, manifestPath, "client edit"); | ||
| return 0; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| #if DEBUG | ||
| logger.LogCritical(ex, "error adding the client: {exceptionMessage}", ex.Message); | ||
| throw; // so debug tools go straight to the source of the exception when attached | ||
| #else | ||
| logger.LogCritical("error adding the client: {exceptionMessage}", ex.Message); | ||
| return 1; | ||
| #endif | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.