private List <string> FindSimilarCommand(string parameter)
        {
            List <string> similarCommands = new List <string>();

            for (int i = 0; i < HelpCommandHandler.CommandsCount(); i++)
            {
                string command = HelpCommandHandler.GetCommandName(i);
                if (LevenshteinDistance(parameter.ToUpperInvariant(), command.ToUpperInvariant()) <= SimilarCoefficient)
                {
                    similarCommands.Add(command);
                }
            }

            return(similarCommands);
        }
Exemple #2
0
        private static void PrintMissedCommandInfo(string command)
        {
            const string similarCommandsMessage = "The most similar commands ";

            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            var similarCommands = new List <string>();

            foreach (var existCommand in HelpCommandHandler.GetListOfExistCommands())
            {
                if (LevenshteinDistance(command, existCommand) < 3)
                {
                    similarCommands.Add(existCommand);
                }
            }

            Console.WriteLine($"FileCabinetApp: '{command}' is not a FileCabinetApp command. See 'help'.");
            Console.WriteLine();
            if (similarCommands.Count == 1)
            {
                Console.Write(similarCommandsMessage);
                Console.WriteLine("is");
            }
            else if (similarCommands.Count > 1)
            {
                Console.Write(similarCommandsMessage);
                Console.WriteLine("are");
            }
            else
            {
                return;
            }

            similarCommands.ForEach(command => Console.WriteLine($"\t\t{command}"));
            Console.WriteLine();
        }