const similarityGroup = require('./helpers/similarity-group');
const importedCommands = require('./commands');
const print = require('./helpers/print');
const packageJson = require('../package.json');

const app = {
  ...importedCommands,

  default(options, commands) {
    if (options.version) {
      return print(packageJson.version);
    }

    return app.help(options, commands);
  },

  notFound({ name }) {
    print(`\`Command named "${name}" not found!\``);

    const similarName = similarityGroup(name, Object.keys(importedCommands));
    if (similarName) {
      print(`\`Did you mean "${similarName}" instead?\``);
    }
  },
};

module.exports = app;
