cli-stash
Version:
CLI application to manage and work with Atlassian Stash. Work with your Stash project and repositories from Command lines.
112 lines (111 loc) • 4.88 kB
JavaScript
"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 tables_1 = require("../../../libs/core/tables");
const ux_1 = require("../../../libs/core/ux");
class Browse 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 {
let result = new stash_connector_1.Page();
if (this.flags.all) {
let tmp = await connector.projects.repos(this.flags.project).browse(this.flags.slug).list({
at: this.flags.at,
type: this.flags.type,
blame: this.flags.blame,
noContent: this.flags['no-content'],
pageOptions: this.allPageOptions
}, this.flags.path);
result.values.push(...tmp.values);
result.isLastPage = true;
result.start = tmp.start;
while (!tmp.isLastPage) {
tmp = await connector.projects.repos(this.flags.project).browse(this.flags.slug).list({
at: this.flags.at,
type: this.flags.type,
blame: this.flags.blame,
noContent: this.flags['no-content'],
pageOptions: {
start: tmp.nextPageStart,
limit: 100,
}
}, this.flags.path);
result.values.push(...tmp.values);
}
result.size = result.values.length;
}
else {
result = await connector.projects.repos(this.flags.project).browse(this.flags.slug).list({
at: this.flags.at,
type: this.flags.type,
blame: this.flags.blame,
noContent: this.flags['no-content'],
pageOptions: this.pageOptions
}, this.flags.path);
}
response.result = result;
response.status = 0;
response.message = result.values.length + ' Lines found';
this.ux.log(response.message);
this.ux.table(result.values, tables_1.LineColumns, {
csv: this.flags.csv,
});
}
catch (error) {
this.processError(response, error);
}
return response;
}
}
exports.default = Browse;
Browse.description = 'Retrieve a page of content for a file path at a specified revision. ' + ux_1.UX.processDocumentation('<doc:Line>');
Browse.examples = [
`$ stash projects:repos:browse -a MyStashAlias --project "ProjectKey" --slug "MyRepoSlug" --all --csv`,
`$ stash projects:repos:browse -a MyStashAlias --project "ProjectKey" --slug "MyRepoSlug" --at "<commmitId>" -l 100 -s 50 --json`,
`$ stash projects:repos:browse -a MyStashAlias --project "ProjectKey" --slug "MyRepoSlug" --type --limit 30`,
];
Browse.flags = {
...baseCommand_1.BaseCommand.flags,
csv: baseCommand_1.BuildFlags.csv,
alias: baseCommand_1.BuildFlags.alias,
...baseCommand_1.BuildFlags.pagination,
project: core_1.Flags.string({
description: 'The Project Key (or user slug like ~userSlug) to browse into the repository',
required: true,
name: 'Project'
}),
slug: core_1.Flags.string({
description: 'The Repository slug to browse',
required: true,
name: 'Slug'
}),
at: core_1.Flags.string({
description: 'The changeset id or ref to retrieve the content for',
required: false,
name: 'At'
}),
type: core_1.Flags.boolean({
description: 'If true only the type will be returned for the file path instead of the contents.',
required: false,
name: 'Type'
}),
blame: core_1.Flags.string({
description: 'If present the blame will be returned for the file as well.',
required: false,
name: 'Blame'
}),
'no-content': core_1.Flags.string({
description: 'If present and used with blame only the blame is retrieved instead of the contents.',
required: false,
name: 'No Content'
}),
path: core_1.Flags.string({
description: 'Retrieve a page of content for a file path at a specified revision.',
required: false,
name: 'Path'
}),
};