// Copyright IBM Corp. 2016. All Rights Reserved.
// Node module: apiconnect-cli-apps
// US Government Users Restricted Rights - Use, duplication or disclosure
// restricted by GSA ADP Schedule Contract with IBM Corp.

/********************************************************* {COPYRIGHT-TOP} ***
 * IBM Confidential
 * OCO Source Materials
 * 5725-C11, 5725-C12, 7198-8FX, 5725-F70, 5725-F71, 5725-F72, 5725-L30
 *
 * (C) Copyright IBM Corporation 2015  All Rights Reserved.
 *
 * The source code for this program is not published or otherwise
 * divested of its trade secrets, irrespective of what has been
 * deposited with the U.S. Copyright Office.
 ********************************************************* {COPYRIGHT-END} **/
/*eslint brace-style: 0, max-len: 0*/

var fs = require('fs');
var path = require('path');

function helpInfo(helpFile) {
  return fs.readFileSync(path.join(__dirname, '..', 'intl', 'en', helpFile),
    'utf-8');
}

module.exports = {
  name: 'apps',
  version: require('../package.json').version,
  path: __filename,
  isBuiltin: true,
  topics: getTopics,
};

function getTopics() {
  return [ {
    name: 'apps',
    description: 'List the apps in organization',
    commands: [
      {
        command: 'list',
        loginRequired: 'app',
        aliases: [ 'apps' ],
        helpInfo: function() {
          return helpInfo('apic_apps_list_help.txt');
        },
        action: function(opts) {
          return require('./plugin-impl').appsListCmd(opts);
        },
        options: [
          '-O, --all-organizations',
          '-o, --organization [providerOrgPath]',
          '-s, --server <server>',
        ],
      },
      {
        command: 'build',
        aliases: [ 'build' ],
        helpInfo: helpInfo('apic_apps_build_help.txt'),
        options: [ '-f, --format <format>', '-n, --no-install', '-s, --scripts' ],
        action: function(opts) {
          return require('./plugin-impl').buildCmd(opts);
        },
      },
      {
        command: 'publish',
        loginRequired: 'app',
        action: function(options) {
          return require('./deploy').deployProject(options);
        },
        options: [
          '-o, --organization <organization>',
          '-s, --server <server>',
          '-a, --app <app>',
          '--project-dir <dir>',
        ],
        helpInfo: helpInfo('apic_apps_publish_help.txt'),
      },
    ],
  } ];
}
