public static void Help(string stringCall = null)
        {
            if (stringCall == null)
            {
                List();
            }
            else
            {
                try
                {
                    // if the call is a library
                    if (!stringCall.Contains(' ') && !stringCall.Contains('.'))
                    {
                        Type library = CParsedInput.ParseLibrary(stringCall);

                        if (library == null)
                        {
                            CFormat.WriteLine("This library does not exist.");
                            return;
                        }

                        string libraryCallName   = CommandManager.ExternalLibraryCallNames.FirstOrDefault(x => x.Value == library).Key;
                        string libraryHelpPrompt = library.GetCustomAttribute <MMasterLibrary>().HelpPrompt;
                        if (!String.IsNullOrEmpty(libraryHelpPrompt))
                        {
                            libraryHelpPrompt = " (" + libraryHelpPrompt + ")";
                        }

                        CFormat.WriteLine(libraryCallName + libraryHelpPrompt, ConsoleColor.Yellow);
                        foreach (MethodInfo methodInfo in CommandManager.ExternalLibraries[library].Values)
                        {
                            MMasterCommand mMasterCommand = methodInfo.GetCustomAttribute <MMasterCommand>();
                            string         helpPrompt     = mMasterCommand.HelpPrompt;
                            if (!String.IsNullOrEmpty(helpPrompt))
                            {
                                helpPrompt = " (" + helpPrompt + ")";
                            }
                            CFormat.WriteLine(CFormat.Indent(3) + "." + methodInfo.Name + helpPrompt);
                        }
                    }
                    else
                    {
                        CParsedInput parsedInput = new CParsedInput(stringCall, true);

                        string helpPrompt = parsedInput.CommandMethodInfo.GetCustomAttribute <MMasterCommand>().HelpPrompt;

                        if (helpPrompt == "")
                        {
                            CFormat.WriteLine(CFormat.GetArgsFormat(parsedInput.FullCallName, parsedInput.CommandMethodInfo.GetParameters()));
                        }
                        else
                        {
                            CFormat.WriteLine(helpPrompt, CFormat.GetArgsFormat(parsedInput.FullCallName, parsedInput.CommandMethodInfo.GetParameters()));
                        }
                    }
                }
                catch (WrongCallFormatException)
                {
                    CFormat.WriteLine("Wrong call format.", "The call should be as it follows: <Library>.<Command> [arg1] [arg2] [etc.]");
                }
                catch (LibraryNotExistingException)
                {
                    CFormat.WriteLine("This library does not exist.");
                }
                catch (CommandNotExistingException)
                {
                    CFormat.WriteLine("This command does not exist.");
                }
            }
        }
 internal MissingArgumentException(CParsedInput parsedInput) : base()
 {
     ParsedInput = parsedInput;
 }
 internal LibraryNotExistingException(CParsedInput parsedInput) : base()
 {
     ParsedInput = parsedInput;
 }
Exemple #4
0
 internal CommandNotExistingException(CParsedInput parsedInput) : base()
 {
     ParsedInput = parsedInput;
 }