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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#nullable enable
#pragma warning disable CS0618

using System.CommandLine;

namespace AI21.CLI.Commands;

internal static partial class CreateProviderKeyGatewaySettingsProviderKeysPostCommandApiCommand
{
private static readonly ProviderKeyCreateOptionSet ProviderKeyCreateOptionSetOptions = ProviderKeyCreateOptionSet.Create();
private static Option<string?> Input { get; } = new(@"--input")
{
Description = "Load request JSON from a file path, '-' for stdin, or an inline JSON object/array string.",
};

private static Option<string?> RequestJson { get; } = new(@"--request-json")
{
Description = "Request body as JSON.",
Hidden = true,
};

private static Option<string?> RequestFile { get; } = new(@"--request-file")
{
Description = "Path to a JSON request file, or '-' for stdin.",
Hidden = true,
};

private static string FormatResponse(ParseResult parseResult, global::AI21.ProviderKeyOut value, global::System.Text.Json.Serialization.JsonSerializerContext context, bool truncateLongStrings)
{
string? text = null;
CustomizeResponseText(parseResult, value, ref text);
if (!string.IsNullOrWhiteSpace(text))
{
return text;
}

var hints = new Dictionary<string, CliFormatHint>(StringComparer.OrdinalIgnoreCase)
{
};
CustomizeResponseFormatHints(hints);
return CliRuntime.FormatHumanReadable(value, context, truncateLongStrings, hints);
}

static partial void CustomizeResponseText(ParseResult parseResult, global::AI21.ProviderKeyOut value, ref string? text);
static partial void CustomizeResponseFormatHints(Dictionary<string, CliFormatHint> hints);


public static Command Create()
{
var command = new Command(@"create-provider-key-gateway-settings-provider-keys-post", @"Create Provider Key
Store a provider key for the workspace. 409 if one already exists.");
command.Options.Add(ProviderKeyCreateOptionSetOptions.Provider);
command.Options.Add(ProviderKeyCreateOptionSetOptions.ApiKey);
command.Options.Add(Input);
command.Options.Add(RequestJson);
command.Options.Add(RequestFile);
command.Validators.Add(result =>
{
var hasInput = result.GetResult(Input) is not null;
var hasRequestJson = result.GetResult(RequestJson) is not null;
var hasRequestFile = result.GetResult(RequestFile) is not null;
var specifiedCount = (hasInput ? 1 : 0) + (hasRequestJson ? 1 : 0) + (hasRequestFile ? 1 : 0);
if (specifiedCount > 1)
{
result.AddError(@"Specify at most one of --input, --request-json, or --request-file.");
}
});

command.SetAction(async (ParseResult parseResult, CancellationToken cancellationToken) =>
await CliRuntime.RunAsync(async () =>
{
var __requestBase = await CliRuntime.ReadRequestOrDefaultAsync<global::AI21.ProviderKeyCreate>(
parseResult,
Input,
RequestJson,
RequestFile,
global::AI21.SourceGenerationContext.Default,
cancellationToken).ConfigureAwait(false); var provider = parseResult.GetRequiredValue(ProviderKeyCreateOptionSetOptions.Provider);
var apiKey = CliRuntime.WasSpecified(parseResult, ProviderKeyCreateOptionSetOptions.ApiKey) ? parseResult.GetValue(ProviderKeyCreateOptionSetOptions.ApiKey) : (__requestBase is { } __ApiKeyBaseValue ? __ApiKeyBaseValue.ApiKey : default);
using var client = await CliRuntime.CreateClientAsync(parseResult, cancellationToken).ConfigureAwait(false);


var response = await client.CreateProviderKeyGatewaySettingsProviderKeysPostAsync(
provider: provider,
apiKey: apiKey,
cancellationToken: cancellationToken).ConfigureAwait(false);


await CliRuntime.WriteResponseAsync(
parseResult,
response,
global::AI21.SourceGenerationContext.Default,
FormatResponse,
cancellationToken).ConfigureAwait(false);
}, cancellationToken).ConfigureAwait(false));
return command;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#nullable enable
#pragma warning disable CS0618

using System.CommandLine;

namespace AI21.CLI.Commands;

internal static partial class CreateProviderKeyTokenwiseSettingsProviderKeysPostCommandApiCommand
{
private static readonly ProviderKeyCreateOptionSet ProviderKeyCreateOptionSetOptions = ProviderKeyCreateOptionSet.Create();
private static Option<string?> Input { get; } = new(@"--input")
{
Description = "Load request JSON from a file path, '-' for stdin, or an inline JSON object/array string.",
};

private static Option<string?> RequestJson { get; } = new(@"--request-json")
{
Description = "Request body as JSON.",
Hidden = true,
};

private static Option<string?> RequestFile { get; } = new(@"--request-file")
{
Description = "Path to a JSON request file, or '-' for stdin.",
Hidden = true,
};

private static string FormatResponse(ParseResult parseResult, global::AI21.ProviderKeyOut value, global::System.Text.Json.Serialization.JsonSerializerContext context, bool truncateLongStrings)
{
string? text = null;
CustomizeResponseText(parseResult, value, ref text);
if (!string.IsNullOrWhiteSpace(text))
{
return text;
}

var hints = new Dictionary<string, CliFormatHint>(StringComparer.OrdinalIgnoreCase)
{
};
CustomizeResponseFormatHints(hints);
return CliRuntime.FormatHumanReadable(value, context, truncateLongStrings, hints);
}

static partial void CustomizeResponseText(ParseResult parseResult, global::AI21.ProviderKeyOut value, ref string? text);
static partial void CustomizeResponseFormatHints(Dictionary<string, CliFormatHint> hints);


public static Command Create()
{
var command = new Command(@"create-provider-key-tokenwise-settings-provider-keys-post", @"Create Provider Key
Store a provider key for the workspace. 409 if one already exists.");
command.Options.Add(ProviderKeyCreateOptionSetOptions.Provider);
command.Options.Add(ProviderKeyCreateOptionSetOptions.ApiKey);
command.Options.Add(Input);
command.Options.Add(RequestJson);
command.Options.Add(RequestFile);
command.Validators.Add(result =>
{
var hasInput = result.GetResult(Input) is not null;
var hasRequestJson = result.GetResult(RequestJson) is not null;
var hasRequestFile = result.GetResult(RequestFile) is not null;
var specifiedCount = (hasInput ? 1 : 0) + (hasRequestJson ? 1 : 0) + (hasRequestFile ? 1 : 0);
if (specifiedCount > 1)
{
result.AddError(@"Specify at most one of --input, --request-json, or --request-file.");
}
});

command.SetAction(async (ParseResult parseResult, CancellationToken cancellationToken) =>
await CliRuntime.RunAsync(async () =>
{
var __requestBase = await CliRuntime.ReadRequestOrDefaultAsync<global::AI21.ProviderKeyCreate>(
parseResult,
Input,
RequestJson,
RequestFile,
global::AI21.SourceGenerationContext.Default,
cancellationToken).ConfigureAwait(false); var provider = parseResult.GetRequiredValue(ProviderKeyCreateOptionSetOptions.Provider);
var apiKey = CliRuntime.WasSpecified(parseResult, ProviderKeyCreateOptionSetOptions.ApiKey) ? parseResult.GetValue(ProviderKeyCreateOptionSetOptions.ApiKey) : (__requestBase is { } __ApiKeyBaseValue ? __ApiKeyBaseValue.ApiKey : default);
using var client = await CliRuntime.CreateClientAsync(parseResult, cancellationToken).ConfigureAwait(false);


var response = await client.CreateProviderKeyTokenwiseSettingsProviderKeysPostAsync(
provider: provider,
apiKey: apiKey,
cancellationToken: cancellationToken).ConfigureAwait(false);


await CliRuntime.WriteResponseAsync(
parseResult,
response,
global::AI21.SourceGenerationContext.Default,
FormatResponse,
cancellationToken).ConfigureAwait(false);
}, cancellationToken).ConfigureAwait(false));
return command;
}
}
Loading