/*
	Licensed Material - Property of IBM

	(C) Copyright 2015 IBM Corp.

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
*/


var path = require('path');
var findExtensions = require('pluggington');

global.MDO_MAIN_EXTENSIONS_PATH = path.join(__dirname, '..', 'node_modules');

var cli = module.exports = {};

cli.commands = {};
cli.commands.help = require('./help');

cli.externalHelp = {};

var extendedCommands = findExtensions(global.MDO_MAIN_EXTENSIONS_PATH, 'mdo.cli.commands');

if (extendedCommands) {
  extendedCommands.forEach(function(commandExtension) {
    var commandName = commandExtension.name;

    if (!cli.commands[commandName]) {
      cli.commands[commandName] = commandExtension.export.run;
      cli.externalHelp[commandName] = commandExtension.export.help;
    }
  });
}
