Skip to content
Draft
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
@@ -1,5 +1,7 @@
using System.Text.Json;
using ChilliCream.Nitro.Client.Apis;
using ChilliCream.Nitro.Client.Clients;
using ChilliCream.Nitro.Client.Stages;
using ChilliCream.Nitro.CommandLine.Helpers;
using ChilliCream.Nitro.CommandLine.Services;
using ChilliCream.Nitro.CommandLine.Services.Configuration;
Expand All @@ -13,8 +15,8 @@ public DownloadClientCommand() : base("download")
{
Description = "Download the queries from a stage.";

Options.Add(Opt<ApiIdOption>.Instance);
Options.Add(Opt<StageNameOption>.Instance);
Options.Add(Opt<OptionalApiIdOption>.Instance);
Options.Add(Opt<OptionalStageNameOption>.Instance);
Options.Add(Opt<FileSystemOutputOptions>.Instance);
Options.Add(Opt<ClientFormatOption>.Instance);

Expand All @@ -38,13 +40,33 @@ private static async Task<int> ExecuteAsync(
{
var console = services.GetRequiredService<INitroConsole>();
var client = services.GetRequiredService<IClientsClient>();
var apisClient = services.GetRequiredService<IApisClient>();
var stagesClient = services.GetRequiredService<IStagesClient>();
var fileSystem = services.GetRequiredService<IFileSystem>();
var sessionService = services.GetRequiredService<ISessionService>();

parseResult.AssertHasAuthentication(sessionService);

var apiId = parseResult.GetRequiredValue(Opt<ApiIdOption>.Instance);
var stageName = parseResult.GetRequiredValue(Opt<StageNameOption>.Instance);
string apiId;
var apiIdArg = parseResult.GetValue(Opt<OptionalApiIdOption>.Instance);
if (console.IsInteractive && string.IsNullOrEmpty(apiIdArg))
{
apiId = await console.GetOrPromptForApiIdAsync(
"For which API?", parseResult, apisClient, sessionService, ct);
}
else
{
apiId = parseResult.GetRequiredOptionalValue(Opt<OptionalApiIdOption>.Instance);
}

var stageName = await console.GetOrPromptForStageNameAsync(
"Which stage?",
parseResult,
Opt<OptionalStageNameOption>.Instance,
stagesClient,
apiId,
ct);

var output = parseResult.GetRequiredValue(Opt<FileSystemOutputOptions>.Instance);
var format = parseResult.GetRequiredValue(Opt<ClientFormatOption>.Instance);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ChilliCream.Nitro.Client;
using ChilliCream.Nitro.Client.Apis;
using ChilliCream.Nitro.Client.Clients;
using ChilliCream.Nitro.Client.Stages;
using ChilliCream.Nitro.CommandLine.Commands.Clients.Components;
using ChilliCream.Nitro.CommandLine.Helpers;
using ChilliCream.Nitro.CommandLine.Results;
Expand All @@ -16,7 +17,7 @@ public ListClientPublishedVersionsCommand() : base("published-versions")
Description = "List all published versions of a client.";

Options.Add(Opt<OptionalClientIdOption>.Instance);
Options.Add(Opt<StageNameOption>.Instance);
Options.Add(Opt<OptionalStageNameOption>.Instance);
Options.Add(Opt<OptionalCursorOption>.Instance);

this.AddGlobalNitroOptions();
Expand All @@ -39,19 +40,21 @@ private static async Task<int> ExecuteAsync(
var console = services.GetRequiredService<INitroConsole>();
var client = services.GetRequiredService<IClientsClient>();
var apisClient = services.GetRequiredService<IApisClient>();
var stagesClient = services.GetRequiredService<IStagesClient>();
var sessionService = services.GetRequiredService<ISessionService>();
var resultHolder = services.GetRequiredService<IResultHolder>();

parseResult.AssertHasAuthentication(sessionService);

var stage = parseResult.GetRequiredValue(Opt<StageNameOption>.Instance);
var cursor = parseResult.GetValue(Opt<OptionalCursorOption>.Instance);

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

var stage = parseResult.GetRequiredOptionalValue(Opt<OptionalStageNameOption>.Instance);

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

Expand All @@ -60,16 +63,17 @@ private static async Task<int> RenderInteractiveAsync(
INitroConsole console,
IClientsClient client,
IApisClient apisClient,
IStagesClient stagesClient,
ISessionService sessionService,
IResultHolder resultHolder,
string stage,
string? cursor,
CancellationToken ct)
{
var clientId = parseResult.GetValue(Opt<OptionalClientIdOption>.Instance);
string? apiId = null;
if (clientId is null)
{
var apiId = await console.GetOrPromptForApiIdAsync(
apiId = await console.GetOrPromptForApiIdAsync(
"For which API do you want to list client versions?",
parseResult, apisClient, sessionService, ct);

Expand All @@ -81,6 +85,21 @@ private static async Task<int> RenderInteractiveAsync(
clientId = selectedClient.Id;
}

var stageArg = parseResult.GetValue(Opt<OptionalStageNameOption>.Instance);
if (string.IsNullOrEmpty(stageArg))
{
apiId ??= await client.GetClientApiIdAsync(clientId, ct)
?? throw new ExitException("The client was not found.");
}

var stage = await console.GetOrPromptForStageNameAsync(
"Which stage?",
parseResult,
Opt<OptionalStageNameOption>.Instance,
stagesClient,
apiId ?? string.Empty,
ct);

var container = PaginationContainer
.CreateConnectionData(async (after, first, cancellationToken) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ internal sealed class ClientTagsToUnpublishOption : Option<IEnumerable<string>>
public ClientTagsToUnpublishOption() : base("--tag")
{
Description = "One or more client version tags to unpublish";
Required = true;
Required = false;
AllowMultipleArgumentsPerToken = true;
this.DefaultFromEnvironmentValue(EnvironmentVariables.Tag);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using ChilliCream.Nitro.Client;
using ChilliCream.Nitro.Client.Apis;
using ChilliCream.Nitro.Client.Clients;
using ChilliCream.Nitro.Client.Stages;
using ChilliCream.Nitro.CommandLine.Commands.Clients.Components;
using ChilliCream.Nitro.CommandLine.Helpers;
using ChilliCream.Nitro.CommandLine.Services.Sessions;
using static ChilliCream.Nitro.CommandLine.ThrowHelper;
Expand All @@ -12,9 +15,9 @@ public PublishClientCommand() : base("publish")
{
Description = "Publish a client version to a stage.";

Options.Add(Opt<ClientIdOption>.Instance);
Options.Add(Opt<TagOption>.Instance);
Options.Add(Opt<StageNameOption>.Instance);
Options.Add(Opt<OptionalClientIdOption>.Instance);
Options.Add(Opt<OptionalTagOption>.Instance);
Options.Add(Opt<OptionalStageNameOption>.Instance);
Options.Add(Opt<OptionalForceOption>.Instance);
Options.Add(Opt<OptionalWaitForApprovalOption>.Instance);
Options.Add(Opt<OptionalSourceMetadataOption>.Instance);
Expand Down Expand Up @@ -51,13 +54,50 @@ private static async Task<int> ExecuteAsync(
{
var console = services.GetRequiredService<INitroConsole>();
var client = services.GetRequiredService<IClientsClient>();
var apisClient = services.GetRequiredService<IApisClient>();
var stagesClient = services.GetRequiredService<IStagesClient>();
var sessionService = services.GetRequiredService<ISessionService>();

parseResult.AssertHasAuthentication(sessionService);

var tag = parseResult.GetRequiredValue(Opt<TagOption>.Instance);
var stage = parseResult.GetRequiredValue(Opt<StageNameOption>.Instance);
var clientId = parseResult.GetRequiredValue(Opt<ClientIdOption>.Instance);
string clientId;
string? apiId = null;
var clientIdArg = parseResult.GetValue(Opt<OptionalClientIdOption>.Instance);
if (console.IsInteractive && clientIdArg is null)
{
apiId = await console.GetOrPromptForApiIdAsync(
"For which API?", parseResult, apisClient, sessionService, ct);

var selectedClient = await SelectClientPrompt
.New(client, apiId)
.Title("Select a client from the list below.")
.RenderAsync(console, ct) ?? throw NoClientSelected();

clientId = selectedClient.Id;
}
else
{
clientId = parseResult.GetRequiredOptionalValue(Opt<OptionalClientIdOption>.Instance);
}

var tag = await console.GetOrPromptForTagAsync(
"Which tag?", parseResult, Opt<OptionalTagOption>.Instance, ct);

var stageArg = parseResult.GetValue(Opt<OptionalStageNameOption>.Instance);
if (string.IsNullOrEmpty(stageArg) && console.IsInteractive)
{
apiId ??= await client.GetClientApiIdAsync(clientId, ct)
?? throw new ExitException("The client was not found.");
}

var stage = await console.GetOrPromptForStageNameAsync(
"Which stage?",
parseResult,
Opt<OptionalStageNameOption>.Instance,
stagesClient,
apiId ?? string.Empty,
ct);

var force = parseResult.GetValue(Opt<OptionalForceOption>.Instance);
var waitForApproval = parseResult.GetValue(Opt<OptionalWaitForApprovalOption>.Instance);
var sourceMetadataJson = parseResult.GetValue(Opt<OptionalSourceMetadataOption>.Instance);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using ChilliCream.Nitro.Client;
using ChilliCream.Nitro.Client.Apis;
using ChilliCream.Nitro.Client.Clients;
using ChilliCream.Nitro.Client.Stages;
using ChilliCream.Nitro.CommandLine.Commands.Clients.Components;
using ChilliCream.Nitro.CommandLine.Commands.Clients.Options;
using ChilliCream.Nitro.CommandLine.Helpers;
using ChilliCream.Nitro.CommandLine.Services.Sessions;
using static ChilliCream.Nitro.CommandLine.ThrowHelper;

namespace ChilliCream.Nitro.CommandLine.Commands.Clients;

Expand All @@ -13,8 +17,8 @@ public UnpublishClientCommand() : base("unpublish")
Description = "Unpublish a client version from a stage.";

Options.Add(Opt<ClientTagsToUnpublishOption>.Instance);
Options.Add(Opt<StageNameOption>.Instance);
Options.Add(Opt<ClientIdOption>.Instance);
Options.Add(Opt<OptionalStageNameOption>.Instance);
Options.Add(Opt<OptionalClientIdOption>.Instance);

this.AddGlobalNitroOptions();

Expand All @@ -36,13 +40,58 @@ private static async Task<int> ExecuteAsync(
{
var console = services.GetRequiredService<INitroConsole>();
var client = services.GetRequiredService<IClientsClient>();
var apisClient = services.GetRequiredService<IApisClient>();
var stagesClient = services.GetRequiredService<IStagesClient>();
var sessionService = services.GetRequiredService<ISessionService>();

parseResult.AssertHasAuthentication(sessionService);

var tags = parseResult.GetRequiredValue(Opt<ClientTagsToUnpublishOption>.Instance).ToArray();
var stage = parseResult.GetRequiredValue(Opt<StageNameOption>.Instance);
var clientId = parseResult.GetRequiredValue(Opt<ClientIdOption>.Instance);
string clientId;
string? apiId = null;
var clientIdArg = parseResult.GetValue(Opt<OptionalClientIdOption>.Instance);
if (console.IsInteractive && clientIdArg is null)
{
apiId = await console.GetOrPromptForApiIdAsync(
"For which API?", parseResult, apisClient, sessionService, cancellationToken);

var selectedClient = await SelectClientPrompt
.New(client, apiId)
.Title("Select a client from the list below.")
.RenderAsync(console, cancellationToken) ?? throw NoClientSelected();

clientId = selectedClient.Id;
}
else
{
clientId = parseResult.GetRequiredOptionalValue(Opt<OptionalClientIdOption>.Instance);
}

var stageArg = parseResult.GetValue(Opt<OptionalStageNameOption>.Instance);
if (string.IsNullOrEmpty(stageArg) && console.IsInteractive)
{
apiId ??= await client.GetClientApiIdAsync(clientId, cancellationToken)
?? throw new ExitException("The client was not found.");
}

var stage = await console.GetOrPromptForStageNameAsync(
"Which stage?",
parseResult,
Opt<OptionalStageNameOption>.Instance,
stagesClient,
apiId ?? string.Empty,
cancellationToken);

var tags = parseResult.GetValue(Opt<ClientTagsToUnpublishOption>.Instance)?.ToArray() ?? [];
if (tags.Length == 0)
{
if (!console.IsInteractive)
{
throw MissingRequiredOption(Opt<ClientTagsToUnpublishOption>.Instance.Name);
}

var tag = await console.PromptAsync("Which tag?", defaultValue: null, cancellationToken);
tags = [tag];
}

await using var activity = console.StartActivity(
$"Unpublishing client '{clientId.EscapeMarkup()}' from stage '{stage.EscapeMarkup()}'",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using ChilliCream.Nitro.Client;
using ChilliCream.Nitro.Client.Apis;
using ChilliCream.Nitro.Client.Clients;
using ChilliCream.Nitro.CommandLine.Commands.Clients.Components;
using ChilliCream.Nitro.CommandLine.Helpers;
using ChilliCream.Nitro.CommandLine.Services;
using ChilliCream.Nitro.CommandLine.Services.Sessions;
Expand All @@ -13,8 +15,8 @@ public UploadClientCommand() : base("upload")
{
Description = "Upload a new client version.";

Options.Add(Opt<ClientIdOption>.Instance);
Options.Add(Opt<TagOption>.Instance);
Options.Add(Opt<OptionalClientIdOption>.Instance);
Options.Add(Opt<OptionalTagOption>.Instance);
Options.Add(Opt<OperationsFileOption>.Instance);
Options.Add(Opt<OptionalSourceMetadataOption>.Instance);

Expand All @@ -38,14 +40,35 @@ private static async Task<int> ExecuteAsync(
{
var console = services.GetRequiredService<INitroConsole>();
var client = services.GetRequiredService<IClientsClient>();
var apisClient = services.GetRequiredService<IApisClient>();
var fileSystem = services.GetRequiredService<IFileSystem>();
var sessionService = services.GetRequiredService<ISessionService>();

parseResult.AssertHasAuthentication(sessionService);

var tag = parseResult.GetRequiredValue(Opt<TagOption>.Instance);
string clientId;
var clientIdArg = parseResult.GetValue(Opt<OptionalClientIdOption>.Instance);
if (console.IsInteractive && clientIdArg is null)
{
var apiId = await console.GetOrPromptForApiIdAsync(
"For which API?", parseResult, apisClient, sessionService, cancellationToken);

var selectedClient = await SelectClientPrompt
.New(client, apiId)
.Title("Select a client from the list below.")
.RenderAsync(console, cancellationToken) ?? throw NoClientSelected();

clientId = selectedClient.Id;
}
else
{
clientId = parseResult.GetRequiredOptionalValue(Opt<OptionalClientIdOption>.Instance);
}

var tag = await console.GetOrPromptForTagAsync(
"Which tag?", parseResult, Opt<OptionalTagOption>.Instance, cancellationToken);

var operationsFilePath = parseResult.GetRequiredValue(Opt<OperationsFileOption>.Instance);
var clientId = parseResult.GetRequiredValue(Opt<ClientIdOption>.Instance);
var sourceMetadataJson = parseResult.GetValue(Opt<OptionalSourceMetadataOption>.Instance);

var source = SourceMetadataParser.Parse(sourceMetadataJson);
Expand Down
Loading
Loading