UNPKG

cli-stash

Version:

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

55 lines (54 loc) 2.43 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 Download 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 { const avatar = await connector.projects.avatar(this.flags.key).get(this.flags.size); response.result = avatar; response.status = 0; response.message = this.getRecordRetrievedText('Project Avatar'); if (!this.flags['output-folder']) { this.ux.log(avatar); } else { const absolutePath = fileSystem_1.PathUtils.getAbsolutePath(this.flags['output-folder']); if (!fileSystem_1.FileChecker.isExists(absolutePath)) { fileSystem_1.FileWriter.createFolderSync(absolutePath); } fileSystem_1.FileWriter.createFileSync(absolutePath + '/Project_' + this.flags.key + '_avatar.png', avatar); } } catch (error) { this.processError(response, error); } return response; } } exports.default = Download; Download.description = 'Retrieve the project matching the supplied projectKey. If not selected output folder, return the raw image data'; Download.examples = [ `$ stash projects:avatar:download -a MyStashAlias --key "ProjectKey"`, `$ stash projects:avatar:download -a MyStashAlias --output-folder "path/to/the/output/folder" --key "ProjectKey" --json`, ]; Download.flags = { ...baseCommand_1.BaseCommand.flags, alias: baseCommand_1.BuildFlags.alias, key: core_1.Flags.string({ description: 'The Project key to retrieve the avatar', required: true, name: 'Key' }), size: core_1.Flags.integer({ description: 'The desired image size', required: false, name: 'Size' }), 'output-folder': baseCommand_1.BuildFlags.output.folder('', false), };