UNPKG

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) 5.03 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) { let tmp = await connector.repos.list({ name: this.flags.name, permission: this.flags.permission, projectname: this.flags.project, visibility: this.flags.visibility, pageOptions: this.allPageOptions }); result.values.push(...tmp.values); result.isLastPage = true; result.start = tmp.start; while (!tmp.isLastPage) { tmp = await connector.repos.list({ name: this.flags.name, permission: this.flags.permission, projectname: this.flags.project, visibility: this.flags.visibility, pageOptions: { start: tmp.nextPageStart, limit: 100, } }); result.values.push(...tmp.values); } result.size = result.values.length; } else { result = await connector.repos.list({ name: this.flags.name, permission: this.flags.permission, projectname: this.flags.project, visibility: this.flags.visibility, pageOptions: this.pageOptions }); } response.result = result; response.status = 0; response.message = this.getRecordsFoundText(result.values.length, 'Repository'); this.ux.log(response.message); this.ux.table(result.values, tables_1.RepositoryColumns, { csv: this.flags.csv, extended: this.flags.extended || this.flags.csv }); } catch (error) { this.processError(response, error); } return response; } } exports.default = List; List.description = 'Retrieve a page of repositories based on query parameters that control the search. ' + ux_1.UX.processDocumentation('<doc:Repository>'); List.examples = [ `$ stash repos:list -a MyStashAlias --project "TheProjectName" --all --csv`, `$ stash repos:list -a MyStashAlias --project "TheProjectName" --permission REPO_READ -l 100 -s 50 --json`, `$ stash repos:list -a MyStashAlias --visibility public --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, name: core_1.Flags.string({ description: ' If specified, this will limit the resulting repository list to ones whose name matches this parameter\'s value. The match will be done case-insensitive and any leading and/or trailing whitespace characters on the name parameter will be stripped.', required: false, name: 'Name' }), project: core_1.Flags.string({ description: 'If specified, this will limit the resulting repository list to ones whose project\'s name matches this parameter\'s value. The match will be done case-insensitive and any leading and/or trailing whitespace characters on the projectname parameter will be stripped', required: false, name: 'Project' }), permission: core_1.Flags.string({ description: 'If specified, it must be a valid repository permission level name and will limit the resulting repository list to ones that the requesting user has the specified permission level to. If not specified, the default implicit "read" permission level will be assumed.', required: false, options: ['REPO_READ', 'REPO_WRITE', 'REPO_ADMIN'], type: "option", name: 'Permission' }), visibility: core_1.Flags.string({ description: 'If specified, this will limit the resulting repository list based on the repositories visibility', required: false, options: ['private', 'public'], type: "option", name: 'Visibility' }), };