Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ private static void ConfigureApiHttpClient(IServiceProvider sp, HttpClient clien
client.DefaultRequestHeaders.Remove("Authorization");
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken.AccessToken}");
break;

case null:
throw new InvalidOperationException(
"You are not authenticated. Either specify --api-key or run 'nitro login'.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private async Task<int> ExecuteAsync(

if (data.Errors?.Count > 0)
{
activity.Fail();
await activity.FailAllAsync();

foreach (var error in data.Errors)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static async Task<int> ExecuteAsync(

if (data.Errors?.Count > 0)
{
activity.Fail();
await activity.FailAllAsync();

foreach (var error in data.Errors)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static async Task<int> ExecuteAsync(
var name = await console.PromptAsync("Name", defaultValue: null, parseResult, Opt<ApiNameOption>.Instance, ct);
var pathResult = await console
.PromptAsync(
"Path [dim](e.g. /foo/bar)[/]",
$"Path {"(e.g. /foo/bar)".Dim()}",
defaultValue: "/",
parseResult,
Opt<ApiPathOption>.Instance,
Expand All @@ -66,7 +66,7 @@ private static async Task<int> ExecuteAsync(

if (payload.Errors?.Count > 0)
{
activity.Fail();
await activity.FailAllAsync();

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

if (changeResult.Error is IError error)
{
activity.Fail();
await activity.FailAllAsync();
console.Error.WriteErrorLine(error.Message);
return ExitCodes.Error;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static async Task<int> ExecuteAsync(
var data = await client.DeleteApiAsync(apiId, cancellationToken);
if (data.Errors?.Count > 0)
{
activity.Fail();
await activity.FailAllAsync();

foreach (var mutationError in data.Errors)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private static async Task<int> ExecuteAsync(

if (data.Errors?.Count > 0)
{
activity.Fail();
await activity.FailAllAsync();

foreach (var mutationError in data.Errors)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public SelectClientPrompt Title(string title)
{
var paginationContainer = PaginationContainer.CreateConnectionData(
async (after, first, ct) => await client.ListClientsAsync(apiId, after, first, ct)
?? throw ThrowHelper.ThereWasAnIssueWithTheRequest("The API was not found."));
?? throw new ExitException("The API was not found."));

return await PagedSelectionPrompt
.New(paginationContainer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private static async Task<int> ExecuteAsync(

if (data.Errors?.Count > 0)
{
activity.Fail();
await activity.FailAllAsync();

foreach (var error in data.Errors)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,17 @@ private static async Task<int> ExecuteAsync(

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

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

if (clientId is null)
{
if (!console.IsInteractive)
{
throw MissingRequiredOption("id");
}

var workspaceId = parseResult.GetWorkspaceId(sessionService);

var selectedApi = await SelectApiPrompt
.New(apisClient, workspaceId)
.Title("For which API do you want to delete a client?")
.RenderAsync(console, cancellationToken) ?? throw NoApiSelected();

var apiId = selectedApi.Id;
var apiId = await console.PromptForApiIdAsync(
apisClient,
workspaceId,
"For which API do you want to delete a client?",
cancellationToken);

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

if (deletedClient.Errors?.Count > 0)
{
activity.Fail();
await activity.FailAllAsync();

foreach (var error in deletedClient.Errors)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using ChilliCream.Nitro.CommandLine.Helpers;
using ChilliCream.Nitro.CommandLine.Results;
using ChilliCream.Nitro.CommandLine.Services.Sessions;
using static ChilliCream.Nitro.CommandLine.ThrowHelper;

namespace ChilliCream.Nitro.CommandLine.Commands.Clients;

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

var cursor = parseResult.GetValue(Opt<OptionalCursorOption>.Instance);
var apiId = await console.GetOrPromptForApiIdAsync(
"For which API do you want to list the clients?",
parseResult,
apisClient,
sessionService,
ct);

if (console.IsInteractive)
{
return await RenderInteractiveAsync(parseResult, console, client, apisClient, sessionService, resultHolder, cursor, ct);
return await RenderInteractiveAsync(console, client, resultHolder, apiId, cursor, ct);
}

return await RenderNonInteractiveAsync(parseResult, client, resultHolder, cursor, ct);
return await RenderNonInteractiveAsync(client, resultHolder, apiId, cursor, ct);
}

private static async Task<int> RenderInteractiveAsync(
ParseResult parseResult,
INitroConsole console,
IClientsClient client,
IApisClient apisClient,
ISessionService sessionService,
IResultHolder resultHolder,
string apiId,
string? cursor,
CancellationToken ct)
{
const string apiMessage = "For which API do you want to list the clients?";
var apiId = await console.GetOrPromptForApiIdAsync(apiMessage, parseResult, apisClient, sessionService, ct);

var container = PaginationContainer
.CreateConnectionData(async (after, first, cancellationToken) =>
await client.ListClientsAsync(apiId, after ?? cursor, first, cancellationToken)
?? throw ThereWasAnIssueWithTheRequest("The API was not found."))
?? throw new ExitException("The API was not found."))
.PageSize(10);

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

private static async Task<int> RenderNonInteractiveAsync(
ParseResult parseResult,
IClientsClient client,
IResultHolder resultHolder,
string apiId,
string? cursor,
CancellationToken ct)
{
var apiId = parseResult.GetValue(Opt<OptionalApiIdOption>.Instance);
if (apiId is null)
{
throw MissingRequiredOption(ApiIdOption.OptionName);
}

var page = await client.ListClientsAsync(apiId, cursor, 10, ct)
?? throw ThereWasAnIssueWithTheRequest("The API was not found.");
?? throw new ExitException("The API was not found.");

var items = page.Items
.Select(x => ClientDetailPrompt.From(x).ToObject())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static async Task<int> RenderInteractiveAsync(
{
var page = await client.ListClientVersionsAsync(
clientId, after ?? cursor, first, cancellationToken)
?? throw ThereWasAnIssueWithTheRequest("The client was not found.");
?? throw new ExitException("The client was not found.");

var mappedItems = page.Items
.Select(ToResult)
Expand Down Expand Up @@ -115,14 +115,10 @@ private static async Task<int> RenderNonInteractiveAsync(
string? cursor,
CancellationToken ct)
{
var clientId = parseResult.GetValue(Opt<OptionalClientIdOption>.Instance);
if (clientId is null)
{
throw MissingRequiredOption("--client-id");
}
var clientId = parseResult.GetRequiredOptionalValue(Opt<OptionalClientIdOption>.Instance);

var page = await client.ListClientVersionsAsync(clientId, cursor, 10, ct)
?? throw ThereWasAnIssueWithTheRequest("The client was not found.");
?? throw new ExitException("The client was not found.");

var items = page.Items
.Select(ToResult)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static async Task<int> RenderInteractiveAsync(
{
var page = await client.ListClientVersionsAsync(
clientId, after ?? cursor, first, cancellationToken)
?? throw ThereWasAnIssueWithTheRequest("The client was not found.");
?? throw new ExitException("The client was not found.");

return new ConnectionPage<ClientVersionResult>(
page.Items.Select(ToResult).ToArray(),
Expand Down Expand Up @@ -110,14 +110,10 @@ private static async Task<int> RenderNonInteractiveAsync(
string? cursor,
CancellationToken ct)
{
var clientId = parseResult.GetValue(Opt<OptionalClientIdOption>.Instance);
if (clientId is null)
{
throw MissingRequiredOption("--client-id");
}
var clientId = parseResult.GetRequiredOptionalValue(Opt<OptionalClientIdOption>.Instance);

var page = await client.ListClientVersionsAsync(clientId, cursor, 10, ct)
?? throw ThereWasAnIssueWithTheRequest("The client was not found.");
?? throw new ExitException("The client was not found.");

var items = page.Items
.Select(ToResult)
Expand Down
Loading
Loading