cli-stash
Version:
CLI application to manage and work with Atlassian Stash. Work with your Stash project and repositories from Command lines.
90 lines (89 loc) • 3.95 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");
class Files 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).files(this.flags.slug).list({
at: this.flags.at,
pageOptions: this.allPageOptions,
});
result.values.push(...tmp.values);
result.isLastPage = true;
result.start = tmp.start;
while (!tmp.isLastPage) {
tmp = await connector.projects.repos(this.flags.project).files(this.flags.slug).list({
at: this.flags.at,
pageOptions: {
start: tmp.nextPageStart,
limit: 100,
}
});
result.values.push(...tmp.values);
}
result.size = result.values.length;
}
else {
result = await connector.projects.repos(this.flags.project).files(this.flags.slug).list({
at: this.flags.at,
pageOptions: this.pageOptions,
});
}
response.result = result;
response.status = 0;
response.message = result.values.length + ' files retrieved';
this.ux.log(response.message);
this.ux.table(result.values, {
file: {
header: 'File'
}
}, {
csv: this.flags.csv,
});
}
catch (error) {
this.processError(response, error);
}
return response;
}
}
exports.default = Files;
Files.description = 'Retrieve a page of files from particular directory of a repository. The search is done recursively, so all files from any sub-directory of the specified directory will be returned.';
Files.examples = [
`$ stash projects:repos:diffs -a MyStashAlias --project "ProjectKey" --slug "MyRepoSlug" --until "as48llmdf" --context-lines 5 --csv`,
`$ stash projects:repos:diffs -a MyStashAlias --project "ProjectKey" --slug "MyRepoSlug" --until "as48llmdf" --src "path/to/src/path" --'without-comments' --json`,
`$ stash projects:repos:diffs -a MyStashAlias --project "ProjectKey" --slug "MyRepoSlug" --until "as48llmdf" --path "path/to/file" --limit 30`,
];
Files.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 get files',
required: true,
name: 'Project'
}),
slug: core_1.Flags.string({
description: 'The Repository slug to get files',
required: true,
name: 'Slug'
}),
at: core_1.Flags.string({
description: 'The changeset id or ref (e.g. a branch or tag) to list the files at. If not specified the default branch will be used instead.',
required: false,
name: 'From'
}),
path: core_1.Flags.string({
description: 'The directory to list files for.',
required: false,
name: 'Path',
}),
};