UNPKG

node_terminus

Version:

Pantheon Terminus cli wrapper and extensions

58 lines (51 loc) 1.44 kB
const Base = require('./base') const _ = require('lodash') const Commands = require('./../../commands.json') const config = require('./../config') const BaseCommand = require('./../classes/baseCommand') let cmds = [] let friendlyName = (v,i,s) =>{ let newName = '' if (v !==':') { newName+=v } else { newName+="_" } return newName } let buildCommands = function(executionArgs, executionOptions){ try { let allCmds = _.map(Commands.commands,(v,i,s)=>{ let tCacheVolumeArg = `-v ${config.cache_path}:/root/.terminus` let returningCmd = new BaseCommand(v.name); let functionFriendlyName = _.join(_.map(returningCmd.name,friendlyName),'') let machineToken; if (returningCmd.name==="auth:login"){ this.machineToken=`--machine-token ${process.env.MACHINE_TOKEN}` } else { this.machineToken='' } _.merge(returningCmd,v); //TODO: Enforce required args? returningCmd.terminus_cmd = ` ${config.base_cmd} ${tCacheVolumeArg} ${config.docker_image} terminus ${returningCmd.name} ${this.machineToken}` cmds[`${functionFriendlyName}`] = returningCmd }) } catch(e) { console.log(e) } } function compileCommands() { let cmds = buildCommands() return cmds; } class GenerateCommands extends Base { constructor() { super() } generate() { compileCommands() return cmds; } } module.exports = GenerateCommands