UNPKG

@codefresh-io/cf-git-providers

Version:

An NPM module/CLI for interacting with various git providers

54 lines 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handler = exports.builder = exports.desc = exports.aliases = exports.command = void 0; const helpers_1 = require("../../../helpers"); // tslint:disable-next-line: no-var-requires const logger = (0, helpers_1.createNewLogger)('codefresh:get:branch'); exports.command = 'branch'; exports.aliases = ['br']; exports.desc = 'Get branch details from a git repository'; const builder = (yargs) => yargs .usage('Usage: $0 get branch [options]') .option('owner', { alias: 'o', demandOption: (0, helpers_1.errormsg) `must provide "owner" option`, describe: 'The name of the owner of the git repository', type: 'string' }) .option('repo', { alias: 'r', demandOption: (0, helpers_1.errormsg) `must provide "repo" option`, describe: 'The name of the git repository', type: 'string' }) .option('branch', { alias: ['b'], describe: 'The name of the branch', type: 'string', default: 'master' }) .example(`$0 get ${exports.command} -o some-owner -r some-repo -n some-branch`, 'Will return the details of the branch named "some-branch" of repo: "some-owner/some-repo"'); exports.builder = builder; const handler = async (argv) => { const owner = argv.owner; const repo = argv.repo; const branch = argv.branch; const provider = argv.provider; const output = argv.output; logger.debug(`owner=${owner}`); logger.debug(`repo=${repo}`); logger.debug(`branch=${branch}`); logger.debug(`output=${output}`); const [getBranchErr, branchRes] = await (0, helpers_1.to)(provider.getBranch({ owner, repo, branch })); if (getBranchErr) { (0, helpers_1.exitWithError)(`failed to get branch "${branch}", ${getBranchErr}`); } if (output) { await (0, helpers_1.writeResultsToFile)(output, branchRes); } else { console.log(JSON.stringify(branchRes)); } }; exports.handler = handler; //# sourceMappingURL=branch.cmd.js.map