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.59 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.hooks.avatar(this.flags.hook).get(this.flags.version); response.result = avatar; response.status = 0; response.message = this.getRecordRetrievedText('Hook 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 + '/Hook' + this.flags.hook + '_avatar.png', avatar); } } catch (error) { this.processError(response, error); } return response; } } exports.default = Download; Download.description = 'Retrieve the avatar for the project matching the supplied moduleKey. If not selected output folder, return the raw image data'; Download.examples = [ `$ stash hooks:avatar:download -a MyStashAlias --hook "HookKey"`, `$ stash hooks:avatar:download -a MyStashAlias --output-folder "path/to/the/output/folder" --hook "HookKey" --json`, ]; Download.flags = { ...baseCommand_1.BaseCommand.flags, alias: baseCommand_1.BuildFlags.alias, hook: core_1.Flags.string({ description: 'The Hook key to retrieve the avatar', required: true, name: 'Hook' }), version: core_1.Flags.integer({ description: 'Optional version used for HTTP caching only - any non-blank version will result in a large max-age Cache-Control header. Note that this does not affect the Last-Modified header.', required: false, name: 'Version' }), 'output-folder': baseCommand_1.BuildFlags.output.folder('', false), };