sesterce-cli
Version:
A powerful command-line interface tool for managing Sesterce Cloud services. Sesterce CLI provides easy access to GPU cloud instances, AI inference services, container registries, and SSH key management directly from your terminal.
96 lines • 3.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createRegistryUpdateCommand = createRegistryUpdateCommand;
const list_registries_1 = require("@/modules/registries/use-cases/list-registries");
const update_registry_1 = require("@/modules/registries/use-cases/update-registry");
const prompts_1 = require("@inquirer/prompts");
const printRegistry = (registry) => {
return `${registry.name} - ${registry.url} - ${registry.username}`;
};
function createRegistryUpdateCommand(registryCommand) {
registryCommand
.command("update")
.description("Update a registry")
.option("-i, --registry-id <registryId>", "The ID of the registry to update")
.action(async (args) => {
var _a;
let registryId = args.registryId;
let registry = null;
console.log("Loading registries...");
const registriesResult = await list_registries_1.listRegistries.execute();
if (registriesResult.isLeft()) {
console.error(registriesResult.value.message);
return;
}
const registries = registriesResult.value;
if (registries.length === 0) {
console.log("No registries found");
return;
}
if (registryId) {
registry = (_a = registries.find((r) => r._id === registryId)) !== null && _a !== void 0 ? _a : null;
}
else {
const selectedRegistry = await (0, prompts_1.search)({
message: "Select a registry to update",
source: async (input, { signal }) => {
if (!input) {
return registries.map((registry) => ({
name: printRegistry(registry),
value: registry,
}));
}
return registries
.filter((registry) => registry.name.toLowerCase().includes(input.toLowerCase()) ||
registry.url.toLowerCase().includes(input) ||
registry.username.toLowerCase().includes(input))
.map((registry) => ({
name: printRegistry(registry),
value: registry,
}));
},
});
registryId = selectedRegistry._id;
registry = selectedRegistry;
}
if (!registry) {
console.error("Registry not found");
return;
}
const url = await (0, prompts_1.input)({
message: "Registry URL",
required: true,
default: registry.url,
validate: (value) => {
// Regex to validate docker.io URLs
const dockerIoRegex = /^docker\.io\/([a-zA-Z0-9_-]+(?:\/[a-zA-Z0-9_-]+)*)\/([a-zA-Z0-9_-]+)(?::([a-zA-Z0-9_.-]+))?$/;
if (!dockerIoRegex.test(value)) {
return "Please enter a valid docker.io URL format: docker.io/username/repo/image[:tag]";
}
return true;
},
});
const username = await (0, prompts_1.input)({
message: "Registry username",
required: true,
default: registry.username,
});
const password = await (0, prompts_1.input)({
message: "Registry password",
required: true,
});
console.log("Updating registry...");
const result = await update_registry_1.updateRegistry.execute({
id: registryId,
url,
username,
password,
});
if (result.isLeft()) {
console.error(result.value.message);
return;
}
console.log("Registry updated successfully!");
});
}
//# sourceMappingURL=update.js.map