How to use didyoumean - 10 common examples

To help you get started, we’ve selected a few didyoumean examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github teambit / bit / src / cli / command-registrar.ts View on Github external
const extensionsCmdList = this.extensionsCommands.map(cmd => first(cmd.name.split(' ')));
    const aliasList = this.commands.map(cmd => first(cmd.alias.split(' ')));

    if (
      cmdList.includes(subcommand) &&
      extensionsCmdList.includes(subcommand) &&
      aliasList.includes(subcommand) &&
      subcommand !== '-V' &&
      subcommand !== '--version'
    ) {
      process.stdout.write(
        chalk.yellow(
          `warning: '${chalk.bold(subcommand)}' is not a valid command.\nsee 'bit --help' for additional information.\n`
        )
      );
      const suggestion = didYouMean(subcommand, commander.commands.filter(c => !c._noHelp).map(cmd => cmd._name));
      if (suggestion) {
        const match = typeof suggestion === 'string' ? suggestion : suggestion[0];
        console.log(chalk.red(`Did you mean ${chalk.bold(match)}?`)); // eslint-disable-line no-console
      }
      return this;
    }

    return this;
  }
github vuejs / vue-cli / packages / @vue / cli / bin / vue.js View on Github external
#!/usr/bin/env node

// Check node version before requiring/doing anything else
// The user may be on a very old node version

const { chalk, semver } = require('@vue/cli-shared-utils')
const requiredVersion = require('../package.json').engines.node
const didYouMean = require('didyoumean')

// Setting edit distance to 60% of the input string's length
didYouMean.threshold = 0.6

function checkNodeVersion (wanted, id) {
  if (!semver.satisfies(process.version, wanted)) {
    console.log(chalk.red(
      'You are using Node ' + process.version + ', but this version of ' + id +
      ' requires Node ' + wanted + '.\nPlease upgrade your Node version.'
    ))
    process.exit(1)
  }
}

checkNodeVersion(requiredVersion, '@vue/cli')

if (semver.satisfies(process.version, '9.x')) {
  console.log(chalk.red(
    `You are using Node ${process.version}.\n` +
github teambit / bit / src / cli / command-registrar.ts View on Github external
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
import commander from 'commander';
import chalk from 'chalk';
import didYouMean from 'didyoumean';
import Command from './command';
import { Commands } from '../extensions/extension';
import { migrate } from '../api/consumer';
import defaultHandleError from './default-error-handler';
import { empty, camelCase, first, isNumeric, buildCommandMessage, packCommand } from '../utils';
import loader from './loader';
import logger from '../logger/logger';
import { Analytics } from '../analytics/analytics';
import { SKIP_UPDATE_FLAG, TOKEN_FLAG, TOKEN_FLAG_NAME } from '../constants';
import globalFlags from './global-flags';

didYouMean.returnFirstMatch = true;

function logAndExit(msg: string, commandName, code = 0) {
  process.stdout.write(`${msg}\n`, () => logger.exitAfterFlush(code, commandName));
}

function logErrAndExit(msg: Error | string, commandName: string) {
  // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
  if (msg.code) throw msg;
  console.error(msg); // eslint-disable-line
  logger.exitAfterFlush(1, commandName);
}

function parseSubcommandFromArgs(args: [any]) {
  if (typeof first(args) === 'string') return first(args);
  return null;
}
github storybookjs / storybook / lib / cli / bin / generate.js View on Github external
program.command('*', { noHelp: true }).action(invalidCmd => {
    logger.error(
      ' Invalid command: %s.\n See --help for a list of available commands.',
      invalidCmd
    );
    // eslint-disable-next-line
    const suggestion = didYouMean(invalidCmd, program.commands.map(cmd => cmd._name)); 
    if (suggestion) {
      logger.log(`\n Did you mean ${suggestion}?`);
    }
    process.exit(1);
  });
github Aceheliflyer / AceBot / src / events / client / unknownCommand.js View on Github external
// Split prefix and get the invalid command used.
    var commandMessage
    // Global Prefix
    if (message.content.startsWith(client.commandPrefix)) {
      commandMessage = message.content.split(client.commandPrefix)[1]
    // Mention Prefix
    } else if (message.content.startsWith(`<@${client.user.id}>`)) {
      commandMessage = message.content.split(`<@${client.user.id}>`)[1]
    // Guild Prefix
    } else if (message.guild && message.guild.commandPrefix !== '') {
      commandMessage = message.content.split(message.guild.commandPrefix)[1]
    }

    // Find the best result.
    didYouMean.threshold = null
    var verify = didYouMean(commandMessage.trim(), possibleCommands)

    // Create the replyMessage.
    var replyMessage = {}
    replyMessage.content = oneLine`
      unknown command, use
      ${message.anyUsage('help')}
      to view the list of all commands.
    `

    // If a match is found, apply it to the replyMessage.
    if (verify) {
      replyMessage.embed = {}
      replyMessage.embed.description = `Did you mean **\`${verify}\`**?`
      replyMessage.embed.color = client.getClientColor(message)
    }
github netbeast / dashboard / bin / cli.js View on Github external
cli.command('restart ')
.description('Restarts a running app')
.action(restart)

cli.command('launch ')
.description('Launches an installed app')
.action(launch)

cli.parse(process.argv)

// No command specified or unrecognaized command
if (cli.args.length === 0) {
  cli.help()
} else if (ACTIONS_LIST.indexOf(process.argv[2]) === -1) {
  didYouMean.threshold = null
  var matched = didYouMean(process.argv[2], ACTIONS_LIST)
  if (matched != null) {
    console.log('\n\tDid you mean "' + didYouMean(process.argv[2], ACTIONS_LIST) + '"?')
    console.log('\n\tType "beast ' + matched + ' -h" to know its parameters' + '\n')
  } else {
    cli.help()
  }
}
github umijs / umi / packages / af-webpack / src / getUserConfig / index.js View on Github external
Object.keys(config).forEach(key => {
    // 禁用项
    if (disabledConfigs.includes(key)) {
      errorMsg = `Configuration item ${key} is disabled, please remove it.`;
    }
    // 非法的项
    if (!pluginNames.includes(key)) {
      const guess = didyoumean(key, pluginNames);
      const affix = guess ? `do you meen ${guess} ?` : 'please remove it.';
      errorMsg = `Configuration item ${key} is not valid, ${affix}`;
    } else {
      // run config plugin's validate
      const plugin = pluginsMapByName[key];
      if (plugin.validate) {
        try {
          plugin.validate.call(context, config[key]);
        } catch (e) {
          errorMsg = e.message;
        }
      }
    }
  });
github madlabsinc / mevn-cli / src / cli.js View on Github external
#!/usr/bin/env node

'use strict';

// Require Modules.
import '@babel/polyfill';
import program from 'commander';
import chalk from 'chalk';
import didYouMean from 'didyoumean';
import envinfo from 'envinfo';
import updateNotifier from 'update-notifier';

// Setting edit distance to 60% of the input string's length.
didYouMean.threshold = 0.6;

// Defining action handlers for respective commands.
import initializeProject from './commands/basic/init';
import generateFile from './commands/basic/generate';
import asyncRender from './commands/basic/codesplit';
import addPlugins from './commands/basic/add';
import setupProject from './commands/serve/setup';
import dockerize from './commands/basic/docker';
import deployConfig from './commands/deploy/deploy';
import pkg from '../package';

updateNotifier({ pkg }).notify();

const suggestCommands = cmd => {
  const availableCommands = program.commands.map(c => c._name);
github xxhomey19 / nba-go / src / cli.js View on Github external
program.command('*').action(command => {
  error(`Unknown command: ${bold(command)}`);

  const commandNames = program.commands
    .map(c => c._name)
    .filter(name => name !== '*');

  const closeMatch = didYouMean(command, commandNames);

  if (closeMatch) {
    error(`Did you mean ${bold(closeMatch)} ?`);
  }

  process.exit(1);
});
github frontity / frontity / packages / frontity / src / actions / unknown.ts View on Github external
export default (command: string, program: CommanderStatic) => {
  console.log(chalk.red(`Unknown command: ${chalk.bold(command)}`));
  console.log();

  const availableCommands: string[] = program.commands.map(c => c._name);
  const suggestion: string | string[] = didYouMean(command, availableCommands);
  
  if (suggestion) {
	console.log(chalk.cyan(`Did you mean '${suggestion}'?`));
	console.log();
  }
  
  program.help();
};

didyoumean

Match human-quality input to potential matches by edit distance.

Apache-2.0
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis