Skip to content

Commit 537f7ec

Browse files
[Nitro CLI] Fix issues with live activity and refine output (#9560)
1 parent 2531c5e commit 537f7ec

142 files changed

Lines changed: 3747 additions & 2319 deletions

File tree

Some content is hidden

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

src/Nitro/CommandLine/src/ChilliCream.Nitro.Client/Extensions/NitroClientServiceCollectionExtensions.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,6 @@ private static void ConfigureApiHttpClient(IServiceProvider sp, HttpClient clien
206206
client.DefaultRequestHeaders.Remove("Authorization");
207207
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken.AccessToken}");
208208
break;
209-
210-
case null:
211-
throw new InvalidOperationException(
212-
"You are not authenticated. Either specify --api-key or run 'nitro login'.");
213209
}
214210
}
215211

src/Nitro/CommandLine/src/CommandLine/Commands/ApiKeys/CreateApiKeyCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private async Task<int> ExecuteAsync(
9696

9797
if (data.Errors?.Count > 0)
9898
{
99-
activity.Fail();
99+
await activity.FailAllAsync();
100100

101101
foreach (var error in data.Errors)
102102
{

src/Nitro/CommandLine/src/CommandLine/Commands/ApiKeys/DeleteApiKeyCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private static async Task<int> ExecuteAsync(
6060

6161
if (data.Errors?.Count > 0)
6262
{
63-
activity.Fail();
63+
await activity.FailAllAsync();
6464

6565
foreach (var error in data.Errors)
6666
{

src/Nitro/CommandLine/src/CommandLine/Commands/Apis/CreateApiCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private static async Task<int> ExecuteAsync(
4848
var name = await console.PromptAsync("Name", defaultValue: null, parseResult, Opt<ApiNameOption>.Instance, ct);
4949
var pathResult = await console
5050
.PromptAsync(
51-
"Path [dim](e.g. /foo/bar)[/]",
51+
$"Path {"(e.g. /foo/bar)".Dim()}",
5252
defaultValue: "/",
5353
parseResult,
5454
Opt<ApiPathOption>.Instance,
@@ -66,7 +66,7 @@ private static async Task<int> ExecuteAsync(
6666

6767
if (payload.Errors?.Count > 0)
6868
{
69-
activity.Fail();
69+
await activity.FailAllAsync();
7070

7171
foreach (var mutationError in payload.Errors)
7272
{
@@ -89,7 +89,7 @@ private static async Task<int> ExecuteAsync(
8989

9090
if (changeResult.Error is IError error)
9191
{
92-
activity.Fail();
92+
await activity.FailAllAsync();
9393
console.Error.WriteErrorLine(error.Message);
9494
return ExitCodes.Error;
9595
}

src/Nitro/CommandLine/src/CommandLine/Commands/Apis/DeleteApiCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private static async Task<int> ExecuteAsync(
6565
var data = await client.DeleteApiAsync(apiId, cancellationToken);
6666
if (data.Errors?.Count > 0)
6767
{
68-
activity.Fail();
68+
await activity.FailAllAsync();
6969

7070
foreach (var mutationError in data.Errors)
7171
{

src/Nitro/CommandLine/src/CommandLine/Commands/Apis/SetApiSettingsCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private static async Task<int> ExecuteAsync(
7272

7373
if (data.Errors?.Count > 0)
7474
{
75-
activity.Fail();
75+
await activity.FailAllAsync();
7676

7777
foreach (var mutationError in data.Errors)
7878
{

src/Nitro/CommandLine/src/CommandLine/Commands/Clients/Components/SelectClientPrompt.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public SelectClientPrompt Title(string title)
2020
{
2121
var paginationContainer = PaginationContainer.CreateConnectionData(
2222
async (after, first, ct) => await client.ListClientsAsync(apiId, after, first, ct)
23-
?? throw ThrowHelper.ThereWasAnIssueWithTheRequest("The API was not found."));
23+
?? throw new ExitException("The API was not found."));
2424

2525
return await PagedSelectionPrompt
2626
.New(paginationContainer)

src/Nitro/CommandLine/src/CommandLine/Commands/Clients/CreateClientCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private static async Task<int> ExecuteAsync(
6262

6363
if (data.Errors?.Count > 0)
6464
{
65-
activity.Fail();
65+
await activity.FailAllAsync();
6666

6767
foreach (var error in data.Errors)
6868
{

src/Nitro/CommandLine/src/CommandLine/Commands/Clients/DeleteClientCommand.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,17 @@ private static async Task<int> ExecuteAsync(
4242

4343
const string clientMessage = "Which client do you want to delete?";
4444

45-
var clientId = parseResult.GetValue(Opt<OptionalIdArgument>.Instance);
45+
var clientId = parseResult.GetRequiredValueIfNotInteractive(Opt<OptionalIdArgument>.Instance, console);
4646

4747
if (clientId is null)
4848
{
49-
if (!console.IsInteractive)
50-
{
51-
throw MissingRequiredOption("id");
52-
}
53-
5449
var workspaceId = parseResult.GetWorkspaceId(sessionService);
5550

56-
var selectedApi = await SelectApiPrompt
57-
.New(apisClient, workspaceId)
58-
.Title("For which API do you want to delete a client?")
59-
.RenderAsync(console, cancellationToken) ?? throw NoApiSelected();
60-
61-
var apiId = selectedApi.Id;
51+
var apiId = await console.PromptForApiIdAsync(
52+
apisClient,
53+
workspaceId,
54+
"For which API do you want to delete a client?",
55+
cancellationToken);
6256

6357
var selectedClient = await SelectClientPrompt
6458
.New(client, apiId)
@@ -96,7 +90,7 @@ private static async Task<int> ExecuteAsync(
9690

9791
if (deletedClient.Errors?.Count > 0)
9892
{
99-
activity.Fail();
93+
await activity.FailAllAsync();
10094

10195
foreach (var error in deletedClient.Errors)
10296
{

src/Nitro/CommandLine/src/CommandLine/Commands/Clients/ListClientCommand.cs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
using ChilliCream.Nitro.CommandLine.Helpers;
55
using ChilliCream.Nitro.CommandLine.Results;
66
using ChilliCream.Nitro.CommandLine.Services.Sessions;
7-
using static ChilliCream.Nitro.CommandLine.ThrowHelper;
8-
97
namespace ChilliCream.Nitro.CommandLine.Commands.Clients;
108

119
internal sealed class ListClientCommand : Command
@@ -41,32 +39,33 @@ private static async Task<int> ExecuteAsync(
4139
parseResult.AssertHasAuthentication(sessionService);
4240

4341
var cursor = parseResult.GetValue(Opt<OptionalCursorOption>.Instance);
42+
var apiId = await console.GetOrPromptForApiIdAsync(
43+
"For which API do you want to list the clients?",
44+
parseResult,
45+
apisClient,
46+
sessionService,
47+
ct);
4448

4549
if (console.IsInteractive)
4650
{
47-
return await RenderInteractiveAsync(parseResult, console, client, apisClient, sessionService, resultHolder, cursor, ct);
51+
return await RenderInteractiveAsync(console, client, resultHolder, apiId, cursor, ct);
4852
}
4953

50-
return await RenderNonInteractiveAsync(parseResult, client, resultHolder, cursor, ct);
54+
return await RenderNonInteractiveAsync(client, resultHolder, apiId, cursor, ct);
5155
}
5256

5357
private static async Task<int> RenderInteractiveAsync(
54-
ParseResult parseResult,
5558
INitroConsole console,
5659
IClientsClient client,
57-
IApisClient apisClient,
58-
ISessionService sessionService,
5960
IResultHolder resultHolder,
61+
string apiId,
6062
string? cursor,
6163
CancellationToken ct)
6264
{
63-
const string apiMessage = "For which API do you want to list the clients?";
64-
var apiId = await console.GetOrPromptForApiIdAsync(apiMessage, parseResult, apisClient, sessionService, ct);
65-
6665
var container = PaginationContainer
6766
.CreateConnectionData(async (after, first, cancellationToken) =>
6867
await client.ListClientsAsync(apiId, after ?? cursor, first, cancellationToken)
69-
?? throw ThereWasAnIssueWithTheRequest("The API was not found."))
68+
?? throw new ExitException("The API was not found."))
7069
.PageSize(10);
7170

7271
var selectedClient = await PagedTable
@@ -85,20 +84,14 @@ await client.ListClientsAsync(apiId, after ?? cursor, first, cancellationToken)
8584
}
8685

8786
private static async Task<int> RenderNonInteractiveAsync(
88-
ParseResult parseResult,
8987
IClientsClient client,
9088
IResultHolder resultHolder,
89+
string apiId,
9190
string? cursor,
9291
CancellationToken ct)
9392
{
94-
var apiId = parseResult.GetValue(Opt<OptionalApiIdOption>.Instance);
95-
if (apiId is null)
96-
{
97-
throw MissingRequiredOption(ApiIdOption.OptionName);
98-
}
99-
10093
var page = await client.ListClientsAsync(apiId, cursor, 10, ct)
101-
?? throw ThereWasAnIssueWithTheRequest("The API was not found.");
94+
?? throw new ExitException("The API was not found.");
10295

10396
var items = page.Items
10497
.Select(x => ClientDetailPrompt.From(x).ToObject())

0 commit comments

Comments
 (0)