UNPKG

28

Version:

Command line utility to download and upload 28.io queries.

38 lines (32 loc) 1.29 kB
'use strict'; var fs = require('fs'); var cli = require('commander'); var Config = require('../config').Config; var $28 = Config.getAPIClient(); //Login Command cli .command('init <config>') .description('Set the 28msec instance to target.') .action(function(config) { if(!config) { console.log('Need email to authenticate: 28 -h for more infos'); return; } var projectConfig = JSON.parse(fs.readFileSync(config, 'utf-8')); var platformEndpoint = projectConfig['28'].platformEndpoint.replace(/dockerhost/, 'localhost'); Config.config.endpoint = platformEndpoint; Config.config.projectEndpoint = platformEndpoint.replace(/portal/, '<%= projectName %>'); Config.save(); console.log(`Signing-in as ${projectConfig['28'].email}...`); $28.login(projectConfig['28'].email, projectConfig['28'].password) .then(function(response){ //console.log(response); //response.body.email = email; Config.save(response.body); console.log('API tokens have been saved.'.green); }) .catch(error => { console.log(error); }) .catch(Config.handleAPIError); });