All files / lib cli.js

100% Statements 88/88
91.66% Branches 11/12
100% Functions 3/3
100% Lines 88/88

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 891x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 4x 3x 3x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
"use strict";
import bag from 'bagofcli';
import Jenkins from './jenkins.js';
import jenkins from './cli/jenkins.js';
import job from './cli/job.js';
import p from 'path';
import _url from 'url';
import view from './cli/view.js';
 
const DIRNAME = p.dirname(import.meta.url).replace('file://', '');
 
function __exec(args, cb) {
  // use url flag or JENKINS_URL environment variable if provided
  const url = (args && args.parent) ? (args.parent.url || process.env.JENKINS_URL) : undefined;
 
  function init(url, cb) {
    const jenkins = new Jenkins(url);
    jenkins.csrf(function (err, result) {
      cb(jenkins);
    });
  }
 
  // if URL value and interactive flag are specified, then prompt for authentication details
  if (url && args.parent && args.parent.interactive) {
    bag.lookupConfig(['Username', 'Password'], { prompt: true }, function (err, results) {
      const parsedUrl = new URL(url);
      parsedUrl.username = results.Username;
      parsedUrl.password = results.Password;
      init(parsedUrl.toString(), cb);
    });
  // otherwise fallback to default URL
  } else {
    init(url, cb);
  }
}
 
/**
 * Execute Nestor CLI.
 */
function exec() {
 
  const actions = {
    commands: {
      'dashboard': { action: jenkins.dashboard(__exec) },
      'discover': { action: jenkins.discover(__exec) },
      'executor': { action: jenkins.executor(__exec) },
      'feed': { action: jenkins.feed(__exec) },
      'queue': { action: jenkins.queue(__exec) },
      'ver': { action: jenkins.version(__exec) },
      'create': { action: job.create(__exec) },
      'create-job': { action: job.create(__exec) },
      'job': { action: job.read(__exec) },
      'read-job': { action: job.read(__exec) },
      'last': { action: job.readLatest(__exec) },
      'update': { action: job.update(__exec) },
      'update-job': { action: job.update(__exec) },
      'delete': { action: job.delete(__exec) },
      'delete-job': { action: job.delete(__exec) },
      'build': { action: job.build(__exec) },
      'build-job': { action: job.build(__exec) },
      'stop': { action: job.stop(__exec) },
      'stop-job': { action: job.stop(__exec) },
      'console': { action: job.console(__exec) },
      'enable': { action: job.enable(__exec) },
      'enable-job': { action: job.enable(__exec) },
      'disable': { action: job.disable(__exec) },
      'disable-job': { action: job.disable(__exec) },
      'copy': { action: job.copy(__exec) },
      'copy-job': { action: job.copy(__exec) },
      'config': { action: job.fetchConfig(__exec) },
      'fetch-job-config': { action: job.fetchConfig(__exec) },
      'create-view': { action: view.create(__exec) },
      'update-view': { action: view.update(__exec) },
      'fetch-view-config': { action: view.fetchConfig(__exec) }
    }
  };
 
  bag.command(DIRNAME, actions);
}
 
const exports = {
  exec: exec,
  __exec: __exec
};
 
export {
  exports as default
};