From 21eb4a79b355cf09d6448a1472e024018b5edf34 Mon Sep 17 00:00:00 2001 From: Damjan Dimitrov Date: Thu, 29 May 2025 10:16:18 +0200 Subject: [PATCH] Add create-bucket CLI command --- package-lock.json | 2 +- packages/cli/README.md | 16 +++++++++++++ packages/cli/package.json | 2 +- .../src/modules/storage/storage.commands.ts | 24 +++++++++++++------ .../src/modules/storage/storage.service.ts | 12 +++++++++- 5 files changed, 46 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 72c11d2..2430621 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7676,7 +7676,7 @@ }, "packages/cli": { "name": "@apillon/cli", - "version": "1.7.1", + "version": "1.8.0", "license": "MIT", "dependencies": { "@apillon/sdk": "*", diff --git a/packages/cli/README.md b/packages/cli/README.md index 7b34828..16b387c 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -247,6 +247,22 @@ apillon hosting get-deployment --website-uuid "123e4567-e89b-12d3-a456-426655440 ## Storage Commands + +#### `storage create-bucket` + +Creates a new storage bucket in your project. + +**Options** + +- `-n, --name `: Name of the new bucket. +- `-d, --description `: Description of the new bucket (optional). + +**Example** + +```sh +apillon storage create-bucket --name "Photo bucket" --description "Vacation photos" +``` + #### `storage list-buckets` Lists all storage buckets associated with your project. diff --git a/packages/cli/package.json b/packages/cli/package.json index d5dcb47..ce73a2a 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,7 +1,7 @@ { "name": "@apillon/cli", "description": "▶◀ Apillon CLI tools ▶◀", - "version": "1.7.1", + "version": "1.8.0", "author": "Apillon", "license": "MIT", "main": "./dist/index.js", diff --git a/packages/cli/src/modules/storage/storage.commands.ts b/packages/cli/src/modules/storage/storage.commands.ts index 2968106..194d47b 100644 --- a/packages/cli/src/modules/storage/storage.commands.ts +++ b/packages/cli/src/modules/storage/storage.commands.ts @@ -1,17 +1,18 @@ +import { FileStatus } from '@apillon/sdk'; import { Command, Option } from 'commander'; import { addPaginationOptions } from '../../lib/options'; +import { enumValues } from '../../lib/utils'; +import { createIpnsCommands } from './ipns.commands'; import { + createBucket, + deleteDirectory, + deleteFile, + getFile, listBuckets, - listObjects, listFiles, + listObjects, uploadFromFolder, - getFile, - deleteFile, - deleteDirectory, } from './storage.service'; -import { FileStatus } from '@apillon/sdk'; -import { enumValues } from '../../lib/utils'; -import { createIpnsCommands } from './ipns.commands'; export function createStorageCommands(cli: Command) { const storage = cli @@ -22,6 +23,15 @@ export function createStorageCommands(cli: Command) { createIpnsCommands(storage); + storage + .command('create-bucket') + .description('Create a new storage bucket') + .requiredOption('-n, --name ', 'Name of the bucket') + .option('-d, --description ', 'Description of the bucket') + .action(async function () { + await createBucket(this.optsWithGlobals()); + }); + const listBucketsCommand = storage .command('list-buckets') .description('List project buckets') diff --git a/packages/cli/src/modules/storage/storage.service.ts b/packages/cli/src/modules/storage/storage.service.ts index 1bffe49..c146645 100644 --- a/packages/cli/src/modules/storage/storage.service.ts +++ b/packages/cli/src/modules/storage/storage.service.ts @@ -1,8 +1,18 @@ import { Storage, toInteger } from '@apillon/sdk'; -import { GlobalOptions } from '../../lib/types'; import { paginate } from '../../lib/options'; +import { GlobalOptions } from '../../lib/types'; import { withErrorHandler } from '../../lib/utils'; +export async function createBucket(optsWithGlobals: GlobalOptions) { + await withErrorHandler(async () => { + const bucket = await new Storage(optsWithGlobals).createBucket({ + name: optsWithGlobals.name, + description: optsWithGlobals.description, + }); + console.log('Bucket created successfully'); + console.log(bucket.serialize()); + }); +} export async function listBuckets(optsWithGlobals: GlobalOptions) { await withErrorHandler(async () => { const data = await new Storage(optsWithGlobals).listBuckets(