UNPKG

cli-stash

Version:

CLI application to manage and work with Atlassian Stash. Work with your Stash project and repositories from Command lines.

50 lines (49 loc) 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const stash_connector_1 = require("stash-connector"); const baseCommand_1 = require("../../../libs/core/baseCommand"); const stashResponse_1 = require("../../../libs/core/stashResponse"); const fileSystem_1 = require("../../../libs/fileSystem"); class Upload extends baseCommand_1.BaseCommand { async run() { const response = new stashResponse_1.StashCLIResponse(); const connector = new stash_connector_1.StashConnector(this.localConfig.getConnectorOptions(this.flags.alias)); try { if (this.flags.file) { const extension = fileSystem_1.PathUtils.getFileExtension(this.flags.file); const absoluePath = fileSystem_1.PathUtils.getAbsolutePath(this.flags.file); if (!extension || extension.toLocaleLowerCase() !== 'png') { throw new Error('Not allowed format. Only PNG images are allowed'); } if (!fileSystem_1.FileChecker.isExists(absoluePath)) { throw new Error('File path ' + absoluePath + ' does not exists'); } } await connector.projects.avatar(this.flags.key).update(this.flags.file); response.status = 0; response.message = 'Project Avatar Uploaded successfully'; this.ux.log(response.message); } catch (error) { this.processError(response, error); } return response; } } exports.default = Upload; Upload.description = 'Update the avatar for the project matching the supplied projectKey.'; Upload.examples = [ `$ stash projects:avatar:upload -a MyStashAlias --key "ProjectKey" --file "path/to/the/avatar/file"`, `$ stash projects:avatar:upload -a MyStashAlias --key "ProjectKey" --file "path/to/the/avatar/file" --json`, ]; Upload.flags = { ...baseCommand_1.BaseCommand.flags, alias: baseCommand_1.BuildFlags.alias, key: core_1.Flags.string({ description: 'The Project key to update the avatar', required: true, name: 'Key' }), file: baseCommand_1.BuildFlags.input.file('', true), };