UNPKG

cli-stash

Version:

CLI application to manage and work with Atlassian Stash. Work with your Stash project and repositories from Command lines.

99 lines (98 loc) 4.93 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 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(); if (this.flags.all) { if (this.flags.none) { let tmp = await connector.projects.permissions(this.flags.project).groups().none(this.flags.filter, this.allPageOptions); result.values.push(...tmp.values); result.isLastPage = true; result.start = tmp.start; while (!tmp.isLastPage) { tmp = await connector.projects.permissions(this.flags.project).groups().none(this.flags.filter, { start: tmp.nextPageStart, limit: 100, }); result.values.push(...tmp.values); } } else { let tmp = await connector.projects.permissions(this.flags.project).groups().list(this.flags.filter, this.allPageOptions); result.values.push(...tmp.values); result.isLastPage = true; result.start = tmp.start; while (!tmp.isLastPage) { tmp = await connector.projects.permissions(this.flags.project).groups().list(this.flags.filter, { start: tmp.nextPageStart, limit: 100, }); result.values.push(...tmp.values); } } result.size = result.values.length; } else { if (this.flags.none) { result = await connector.projects.permissions(this.flags.project).groups().none(this.flags.filter, this.pageOptions); } else { result = await connector.projects.permissions(this.flags.project).groups().list(this.flags.filter, this.pageOptions); } } response.result = result; response.status = 0; if (this.flags.none) { response.message = this.getRecordsFoundText(result.values.length, 'Groups'); this.ux.log(response.message); this.ux.table(result.values, tables_1.GroupColumns, { csv: this.flags.csv, }); } else { response.message = this.getRecordsFoundText(result.values.length, 'Group Permissions'); this.ux.log(response.message); this.ux.table(result.values, tables_1.GroupPermissionsColumns, { csv: this.flags.csv, }); } } catch (error) { this.processError(response, error); } return response; } } exports.default = List; List.description = 'Retrieve a page of groups that have been granted at least one permission for the specified project, or retrieve a page of Groups without any permission for the specified project. ' + ux_1.UX.processDocumentation('<doc:PermissionGroups>'); List.examples = [ `$ stash projects:permissions:groups:list -a MyStashAlias --project "ProjectKey" --all`, `$ stash projects:permissions:groups:list -a MyStashAlias --project "ProjectKey" --none -l 100 -s 50`, `$ stash projects:permissions:groups:list -a MyStashAlias --project "ProjectKey" --filter "groupName" --limit 30`, ]; 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, project: core_1.Flags.string({ description: 'The Project key to get the groups', required: true, name: 'Project' }), filter: baseCommand_1.BuildFlags.filter('If specified only group names containing the supplied string will be returned'), none: core_1.Flags.boolean({ description: 'Retrieve a page of groups that have no granted global permissions. ' + ux_1.UX.processDocumentation('<doc:Group>'), name: 'None' }), };