cli-stash
Version:
CLI application to manage and work with Atlassian Stash. Work with your Stash project and repositories from Command lines.
103 lines (102 loc) • 4.76 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 List 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();
const options = {
filter: this.flags.filter,
context: this.flags.context,
pageOptions: this.flags.all ? this.allPageOptions : this.pageOptions,
};
if (this.flags.all) {
if (this.flags.members) {
let tmp = await connector.admin.groups().members(options);
result.values.push(...tmp.values);
result.isLastPage = true;
result.start = tmp.start;
while (!tmp.isLastPage) {
tmp = await connector.admin.groups().members({
filter: this.flags.filter,
context: this.flags.context,
pageOptions: {
start: tmp.nextPageStart,
limit: 100,
},
});
result.values.push(...tmp.values);
}
}
else {
let tmp = await connector.admin.groups().nonMembers(options);
result.values.push(...tmp.values);
result.isLastPage = true;
result.start = tmp.start;
while (!tmp.isLastPage) {
tmp = await connector.admin.groups().nonMembers({
filter: this.flags.filter,
context: this.flags.context,
pageOptions: {
start: tmp.nextPageStart,
limit: 100,
},
});
result.values.push(...tmp.values);
}
}
result.size = result.values.length;
}
else {
if (this.flags.members) {
result = await connector.admin.groups().members(options);
}
else {
result = await connector.admin.groups().nonMembers(options);
}
}
const message = this.getRecordsFoundText(result.values.length, 'User');
response.result = result;
response.status = 0;
response.message = message;
this.ux.log(response.message);
this.ux.table(result.values, tables_1.UserColumns, {
csv: this.flags.csv,
extended: this.flags.extended || this.flags.csv
});
}
catch (error) {
this.processError(response, error);
}
return response;
}
}
exports.default = List;
List.description = 'List the members or non members from a group. By default, list all members' + ux_1.UX.processDocumentation('<doc:User>');
List.examples = [
`$ stash admin:groups:members:list -a MyStashAlias --filter "FilterValue" --members`,
`$ stash admin:groups:members:list -a MyStashAlias --members --json --start 0 --limit 100`,
`$ stash admin:groups:members:list -a MyStashAlias --no-members --csv --all --extended`,
];
List.flags = {
...baseCommand_1.BaseCommand.flags,
csv: baseCommand_1.BuildFlags.csv,
extended: baseCommand_1.BuildFlags.extended,
alias: baseCommand_1.BuildFlags.alias,
...baseCommand_1.BuildFlags.pagination,
filter: baseCommand_1.BuildFlags.filter('If specified only users with usernames, display names or email addresses containing the supplied string will be returned'),
context: baseCommand_1.BuildFlags.context('The group which should be used to locate members'),
members: core_1.Flags.boolean({
description: 'List group members. if use --no-members, will list all not member users',
allowNo: true,
required: false,
default: true,
}),
};