UNPKG

@rockset/cli

Version:
82 lines (81 loc) 3.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const core_2 = require("@rockset/core"); const fileutil_1 = require("@rockset/core/dist/filesystem/fileutil"); const base_command_1 = require("../../base-command"); let ResolvePath = /** @class */ (() => { class ResolvePath extends base_command_1.RockCommand { async run() { const { args, flags } = await this.parse(ResolvePath); // These must be specified, as they are marked required above const entity = flags.entity; const name = args.name; // Report the path to the user const reportPath = async (p) => { if ((await core_2.fileutil.exists(p)) || !flags.exists) { this.log(p); } else { this.error(`The entity "${name}" resolves to path '${p}', which does not exist.`); } }; // In the case of a lambda if (entity === 'lambda') { const qualifiedName = core_2.types.parseLambdaQualifiedName(name); if (flags.sql) { const path = await core_2.fileutil .getLambdaSqlPathFromQualifiedName(qualifiedName) .catch((error) => { this.error(`There was an error while trying to parse your lambda config. Are you sure this lambda exists and is formatted correctly? ${error}`); }); await reportPath(path); } else { const srcPath = await fileutil_1.getSrcPath(); const p = core_2.pathutil.resolvePathFromQualifiedName(qualifiedName, entity, srcPath); await reportPath(p); } } else { // This is a workspace const qualifiedName = core_2.types.parseWorkspaceQualifiedName(name); const srcPath = await fileutil_1.getSrcPath(); const p = core_2.pathutil.resolvePathFromQualifiedName(qualifiedName, entity, srcPath); await reportPath(p); } } } ResolvePath.flags = { help: core_1.Flags.help({ char: 'h' }), entity: core_1.Flags.string({ char: 'e', options: ['lambda', 'workspace'], default: 'lambda', description: 'the type of entity you wish to resolve', }), exists: core_1.Flags.boolean({ description: 'return with an error if file does not exist', default: true, allowNo: true, }), sql: core_1.Flags.boolean({ description: 'return the SQL file path (only for Query Lambdas)', }), }; ResolvePath.args = [ { name: 'name', required: true, hidden: false, description: 'the fully qualified name of the lambda you wish to resolve (eg. "{workspace}.{name}") ', }, ]; ResolvePath.description = `resolve the absolute path of an entity in the current project`; ResolvePath.examples = [ `$ rockset local:resolve commons.myLambda`, `$ rockset local:resolve commons.myLambda --sql`, ]; return ResolvePath; })(); exports.default = ResolvePath;