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.27 kB
JavaScript
;
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.users.avatar(this.flags.slug).update(this.flags.file);
response.status = 0;
response.message = 'User 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 user with the supplied slug.';
Upload.examples = [
`$ stash projects:avatar:upload -a MyStashAlias --slug "userslug" --file "path/to/the/avatar/file"`,
`$ stash projects:avatar:upload -a MyStashAlias --slug "userslug" --file "path/to/the/avatar/file" --json`,
];
Upload.flags = {
...baseCommand_1.BaseCommand.flags,
alias: baseCommand_1.BuildFlags.alias,
slug: core_1.Flags.string({
description: 'The user slug to update the avatar',
required: true,
name: 'User Slug'
}),
file: baseCommand_1.BuildFlags.input.file('', true),
};