How to use the didyoumean.returnFirstMatch function in didyoumean

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

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;
}

didyoumean

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

Apache-2.0
Latest version published 1 year ago

Package Health Score

67 / 100
Full package analysis

Similar packages