-
-
Notifications
You must be signed in to change notification settings - Fork 803
[Nitro CLI] Add stage delete command #9417
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
8 commits
Select commit
Hold shift + click to select a range
833636f
cleanup
PascalSenn 67f54ec
cleanup
PascalSenn 3f636d0
cleanup
PascalSenn c994efe
cleanup
PascalSenn 96395bd
cleanup
PascalSenn 7064a7d
Merge branch 'main' into pse/add-nitr-stage-delete
PascalSenn bd1a106
Apply suggestion from @PascalSenn
PascalSenn f0632ee
generate cli
PascalSenn 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
76 changes: 76 additions & 0 deletions
76
src/Nitro/CommandLine/src/CommandLine/Commands/Stages/DeleteStageCommand.cs
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,76 @@ | ||
| using System.CommandLine.Invocation; | ||
| using ChilliCream.Nitro.CommandLine.Client; | ||
| using ChilliCream.Nitro.CommandLine.Commands.Apis.Inputs; | ||
| using ChilliCream.Nitro.CommandLine.Commands.Stages.Components; | ||
| using ChilliCream.Nitro.CommandLine.Configuration; | ||
| using ChilliCream.Nitro.CommandLine.Helpers; | ||
| using ChilliCream.Nitro.CommandLine.Options; | ||
| using ChilliCream.Nitro.CommandLine.Results; | ||
| using ChilliCream.Nitro.CommandLine.Services.Sessions; | ||
| using static ChilliCream.Nitro.CommandLine.ThrowHelper; | ||
|
|
||
| namespace ChilliCream.Nitro.CommandLine.Commands.Stages; | ||
|
|
||
| internal sealed class DeleteStageCommand : Command | ||
| { | ||
| public DeleteStageCommand() : base("delete") | ||
| { | ||
| Description = "Deletes a stage by name"; | ||
|
|
||
| AddOption(Opt<OptionalApiIdOption>.Instance); | ||
| AddOption(Opt<StageNameOption>.Instance); | ||
| AddOption(Opt<ForceOption>.Instance); | ||
|
|
||
| this.SetHandler( | ||
| ExecuteAsync, | ||
| Bind.FromServiceProvider<InvocationContext>(), | ||
| Bind.FromServiceProvider<IAnsiConsole>(), | ||
| Bind.FromServiceProvider<IApiClient>(), | ||
| Bind.FromServiceProvider<CancellationToken>()); | ||
| } | ||
|
|
||
| private static async Task<int> ExecuteAsync( | ||
| InvocationContext context, | ||
| IAnsiConsole console, | ||
| IApiClient client, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| const string apiMessage = "For which API do you want to force delete a stage?"; | ||
| var apiId = await context.GetOrSelectApiId(apiMessage); | ||
|
|
||
| var stageName = context.ParseResult.GetValueForOption(Opt<StageNameOption>.Instance)!; | ||
|
|
||
| var shouldDelete = await context.ConfirmWhenNotForced( | ||
| $"Do you really want to force delete stage {stageName.AsHighlight()}", | ||
| cancellationToken); | ||
|
|
||
| if (!shouldDelete) | ||
| { | ||
| throw Exit("Stage was not deleted"); | ||
|
PascalSenn marked this conversation as resolved.
|
||
| } | ||
|
|
||
| var input = new ForceDeleteStageByApiIdInput { ApiId = apiId, StageName = stageName }; | ||
| var result = await client.ForceDeleteStageByApiIdCommandMutation | ||
| .ExecuteAsync(input, cancellationToken); | ||
|
|
||
| console.EnsureNoErrors(result); | ||
| var data = console.EnsureData(result); | ||
| console.PrintErrorsAndExit(data.ForceDeleteStageByApiId.Errors); | ||
|
|
||
| var api = data.ForceDeleteStageByApiId.Api; | ||
| if (api is null) | ||
| { | ||
| throw Exit("Could not delete the stage"); | ||
| } | ||
|
|
||
| var items = api.Stages | ||
| .Select(x => StageDetailPrompt.From(x).ToObject()) | ||
| .ToArray(); | ||
|
|
||
| context.SetResult(new PaginatedListResult<StageDetailPrompt.StageDetailPromptResult>(items, null)); | ||
|
|
||
| console.OkLine($"Stage {stageName.AsHighlight()} was force deleted"); | ||
|
|
||
| return ExitCodes.Success; | ||
| } | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
src/Nitro/CommandLine/src/CommandLine/Commands/Stages/DeleteStageCommand.graphql
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,15 @@ | ||
| mutation ForceDeleteStageByApiIdCommandMutation($input: ForceDeleteStageByApiIdInput!) { | ||
| forceDeleteStageByApiId(input: $input) { | ||
| api { | ||
| stages { | ||
| ...StageDetailPrompt_Stage | ||
| } | ||
| } | ||
| errors { | ||
| ...Error | ||
| ...ApiNotFoundError | ||
| ...StageNotFoundError | ||
| ...UnauthorizedOperation | ||
| } | ||
| } | ||
| } |
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.
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.