-
-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): impl bucket curd cmd (#683)
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { bucketControllerCreate, bucketControllerFindAll, bucketControllerRemove, bucketControllerUpdate } from "../../api/v1/storage"; | ||
import { readApplicationConfig } from "../../config/application"; | ||
import * as Table from 'cli-table3'; | ||
import * as prompts from 'prompts'; | ||
import { CreateBucketDto, UpdateBucketDto } from "../../api/v1/data-contracts"; | ||
import { getEmoji } from "../../util/print"; | ||
|
||
|
||
export async function list() { | ||
const appConfig = readApplicationConfig() | ||
const buckets = await bucketControllerFindAll(appConfig.appid) | ||
const table = new Table({ | ||
head: ['name', 'shortName', 'policy', 'updatedAt'], | ||
}) | ||
for (let item of buckets) { | ||
table.push([item.name, item.shortName, item.policy, item.updatedAt]) | ||
} | ||
console.log(table.toString()); | ||
} | ||
|
||
|
||
const policySelect = { | ||
type: 'select', | ||
name: 'policy', | ||
message: 'please select policy', | ||
choices: [ | ||
{ title: 'private', value: 'private' }, | ||
{ title: 'readonly', value: 'readonly' }, | ||
{ title: 'readwrite', value: 'readwrite' } | ||
], | ||
}; | ||
|
||
|
||
export async function create(bucketName, options) { | ||
if (options) { | ||
|
||
} | ||
const appConfig = readApplicationConfig() | ||
console.log('please select bucket storage policy') | ||
const policyResult = await prompts(policySelect); | ||
const bucketDto: CreateBucketDto = { | ||
shortName: bucketName, | ||
policy: policyResult.policy, | ||
} | ||
await bucketControllerCreate(appConfig.appid, bucketDto) | ||
console.log(`${getEmoji('✅')} bucket ${bucketName} created`) | ||
} | ||
|
||
export async function update(bucketName, options) { | ||
if (options) { } | ||
const appConfig = readApplicationConfig() | ||
console.log('please select the storage policy to be replaced') | ||
const policyResult = await prompts(policySelect); | ||
const bucketDto: UpdateBucketDto = { | ||
policy: policyResult.policy, | ||
} | ||
await bucketControllerUpdate(appConfig.appid, bucketName, bucketDto) | ||
console.log(`${getEmoji('✅')} bucket ${bucketName} updated`) | ||
} | ||
|
||
export async function del(bucketName, options) { | ||
if (options) { | ||
|
||
} | ||
const appConfig = readApplicationConfig() | ||
await bucketControllerRemove(appConfig.appid, bucketName) | ||
console.log(`${getEmoji('✅')} bucket ${bucketName} deleted`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Command, program } from "commander" | ||
import { create, del, list, update } from "../../action/stroage" | ||
import { checkApplication } from "../../common/hook" | ||
|
||
export function bucketCommand(): Command { | ||
const cmd = program.command('bucket') | ||
.hook('preAction', () => { | ||
checkApplication() | ||
}) | ||
|
||
cmd.command('list') | ||
.description('bucket list') | ||
.action(() => { | ||
list() | ||
}) | ||
|
||
cmd.command('create <bucketName>') | ||
.description('create a bucket') | ||
.action((bucketName, options) => { | ||
create(bucketName, options) | ||
}) | ||
|
||
cmd.command('update <bucketName>') | ||
.description('update bucket') | ||
.action((bucketName, options) => { | ||
update(bucketName, options) | ||
}) | ||
|
||
cmd.command('del <bucketName>') | ||
.description('delete bucket') | ||
.action((bucketName, options) => { | ||
del(bucketName, options) | ||
}) | ||
|
||
|
||
return cmd | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters