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
2 changes: 2 additions & 0 deletions src/cli/Baseten.CLI/Commands/ApiCommand.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public static Command Create()
var command = new Command("api", "Generated endpoint commands.");

command.Subcommands.Add(DefaultApiGroupCommand.Create());
command.Subcommands.Add(ImagesApiGroupCommand.Create());
command.Subcommands.Add(SandboxesApiGroupCommand.Create());
CustomizeCommand(ref command);
return command;
}
Expand Down
24 changes: 24 additions & 0 deletions src/cli/Baseten.CLI/Commands/ImagesApiGroupCommand.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#nullable enable

using System.CommandLine;

namespace Baseten.CLI.Commands;

internal static partial class ImagesApiGroupCommand
{
static partial void CustomizeCommand(ref Command command);

public static Command Create()
{
var command = new Command(@"images", @"Images endpoint commands.");
command.Subcommands.Add(ImagesCleanupImagesCommandApiCommand.Create());
command.Subcommands.Add(ImagesDeleteImageCommandApiCommand.Create());
command.Subcommands.Add(ImagesDeleteImageTagCommandApiCommand.Create());
command.Subcommands.Add(ImagesGetImageCommandApiCommand.Create());
command.Subcommands.Add(ImagesListImageTagsCommandApiCommand.Create());
command.Subcommands.Add(ImagesListImagesCommandApiCommand.Create());
command.Subcommands.Add(ImagesPushImageCommandApiCommand.Create());
CustomizeCommand(ref command);
return command;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#nullable enable
#pragma warning disable CS0618

using System.CommandLine;

namespace Baseten.CLI.Commands;

internal static partial class ImagesCleanupImagesCommandApiCommand
{
private static Option<string?> TeamId { get; } = new(
name: @"--team-id")
{
Description = @"Optional team ID. Must match X-Team-Id when both are supplied. If neither selector is supplied, defaults to the caller's only accessible team. Callers with multiple accessible teams must select a team. Requests without access to any team are forbidden.",
};

private static Option<string?> XTeamId { get; } = new(
name: @"--x-team-id")
{
Description = @"Optional team ID. Must match the team_id query parameter when both are supplied. If neither selector is supplied, defaults to the caller's only accessible team. Callers with multiple accessible teams must select a team. Requests without access to any team are forbidden.",
};

private static string FormatResponse(ParseResult parseResult, global::Baseten.CleanupImagesResponseV1 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::Baseten.CleanupImagesResponseV1 value, ref string? text);
static partial void CustomizeResponseFormatHints(Dictionary<string, CliFormatHint> hints);


static partial void CustomizeCommand(ref Command command);

public static Command Create(string? commandName = null)
{
var command = new Command(commandName ?? @"cleanup-images", @"Clean up unused images
Remove unused sandbox image versions. Versions referenced by active deployments are preserved.");
command.Options.Add(TeamId);
command.Options.Add(XTeamId);


command.SetAction(async (ParseResult parseResult, CancellationToken cancellationToken) =>
await CliRuntime.RunAsync(async () =>
{
var teamId = parseResult.GetValue(TeamId);
var xTeamId = parseResult.GetValue(XTeamId);
using var client = await CliRuntime.CreateClientAsync(parseResult, cancellationToken).ConfigureAwait(false);


var response = await client.Images.CleanupImagesAsync(
teamId: teamId,
xTeamId: xTeamId,
cancellationToken: cancellationToken).ConfigureAwait(false);


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

using System.CommandLine;

namespace Baseten.CLI.Commands;

internal static partial class ImagesDeleteImageCommandApiCommand
{
private static Argument<string> ImageName { get; } = new(
name: @"image-name")
{
Description = @"This is a missing parameter that was added automatically. Please check the OpenAPI spec.",
};

private static Option<string?> TeamId { get; } = new(
name: @"--team-id")
{
Description = @"Optional team ID. Must match X-Team-Id when both are supplied. If neither selector is supplied, defaults to the caller's only accessible team. Callers with multiple accessible teams must select a team. Requests without access to any team are forbidden.",
};

private static Option<string?> XTeamId { get; } = new(
name: @"--x-team-id")
{
Description = @"Optional team ID. Must match the team_id query parameter when both are supplied. If neither selector is supplied, defaults to the caller's only accessible team. Callers with multiple accessible teams must select a team. Requests without access to any team are forbidden.",
};

private static string FormatResponse(ParseResult parseResult, global::Baseten.ImageV1 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::Baseten.ImageV1 value, ref string? text);
static partial void CustomizeResponseFormatHints(Dictionary<string, CliFormatHint> hints);


static partial void CustomizeCommand(ref Command command);

public static Command Create(string? commandName = null)
{
var command = new Command(commandName ?? @"delete-image", @"Delete a sandbox image
Delete the image repository and all its tags. Reject deletion if any version is referenced by an active deployment. Return the deleted image.");
command.Arguments.Add(ImageName);
command.Options.Add(TeamId);
command.Options.Add(XTeamId);


command.SetAction(async (ParseResult parseResult, CancellationToken cancellationToken) =>
await CliRuntime.RunAsync(async () =>
{
var imageName = parseResult.GetRequiredValue(ImageName);
var teamId = parseResult.GetValue(TeamId);
var xTeamId = parseResult.GetValue(XTeamId);
using var client = await CliRuntime.CreateClientAsync(parseResult, cancellationToken).ConfigureAwait(false);


var response = await client.Images.DeleteImageAsync(
imageName: imageName,
teamId: teamId,
xTeamId: xTeamId,
cancellationToken: cancellationToken).ConfigureAwait(false);


if (!await CliRuntime.TryWriteOutputDirectoryAsync(
parseResult,
response,
global::Baseten.SourceGenerationContext.Default,
@"Tags",
cancellationToken).ConfigureAwait(false))
{
await CliRuntime.WriteResponseAsync(
parseResult,
response,
global::Baseten.SourceGenerationContext.Default,
FormatResponse,
cancellationToken).ConfigureAwait(false);
}
}, cancellationToken).ConfigureAwait(false));
CustomizeCommand(ref command);
return command;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#nullable enable
#pragma warning disable CS0618

using System.CommandLine;

namespace Baseten.CLI.Commands;

internal static partial class ImagesDeleteImageTagCommandApiCommand
{
private static Argument<string> ImageName { get; } = new(
name: @"image-name")
{
Description = @"This is a missing parameter that was added automatically. Please check the OpenAPI spec.",
};

private static Argument<string> TagName { get; } = new(
name: @"tag-name")
{
Description = @"This is a missing parameter that was added automatically. Please check the OpenAPI spec.",
};

private static Option<string?> TeamId { get; } = new(
name: @"--team-id")
{
Description = @"Optional team ID. Must match X-Team-Id when both are supplied. If neither selector is supplied, defaults to the caller's only accessible team. Callers with multiple accessible teams must select a team. Requests without access to any team are forbidden.",
};

private static Option<string?> XTeamId { get; } = new(
name: @"--x-team-id")
{
Description = @"Optional team ID. Must match the team_id query parameter when both are supplied. If neither selector is supplied, defaults to the caller's only accessible team. Callers with multiple accessible teams must select a team. Requests without access to any team are forbidden.",
};

private static string FormatResponse(ParseResult parseResult, global::Baseten.ImageV1 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::Baseten.ImageV1 value, ref string? text);
static partial void CustomizeResponseFormatHints(Dictionary<string, CliFormatHint> hints);


static partial void CustomizeCommand(ref Command command);

public static Command Create(string? commandName = null)
{
var command = new Command(commandName ?? @"delete-image-tag", @"Delete an image tag
Delete a specific image version. Reject deletion if the version is referenced by an active deployment. Return the updated image with its remaining tags, possibly empty.");
command.Arguments.Add(ImageName);
command.Arguments.Add(TagName);
command.Options.Add(TeamId);
command.Options.Add(XTeamId);


command.SetAction(async (ParseResult parseResult, CancellationToken cancellationToken) =>
await CliRuntime.RunAsync(async () =>
{
var imageName = parseResult.GetRequiredValue(ImageName);
var tagName = parseResult.GetRequiredValue(TagName);
var teamId = parseResult.GetValue(TeamId);
var xTeamId = parseResult.GetValue(XTeamId);
using var client = await CliRuntime.CreateClientAsync(parseResult, cancellationToken).ConfigureAwait(false);


var response = await client.Images.DeleteImageTagAsync(
imageName: imageName,
tagName: tagName,
teamId: teamId,
xTeamId: xTeamId,
cancellationToken: cancellationToken).ConfigureAwait(false);


if (!await CliRuntime.TryWriteOutputDirectoryAsync(
parseResult,
response,
global::Baseten.SourceGenerationContext.Default,
@"Tags",
cancellationToken).ConfigureAwait(false))
{
await CliRuntime.WriteResponseAsync(
parseResult,
response,
global::Baseten.SourceGenerationContext.Default,
FormatResponse,
cancellationToken).ConfigureAwait(false);
}
}, cancellationToken).ConfigureAwait(false));
CustomizeCommand(ref command);
return command;
}
}
Loading
Loading