Ejemplo n.º 1
0
 public CommandPage(DocumentSet <IDocument> documentSet, ICommandLineHelpPathProvider pathProvider, CommandDocumentation model, CommandLineHelpConfiguration configuration)
 {
     m_DocumentSet   = documentSet ?? throw new ArgumentNullException(nameof(documentSet));
     m_PathProvider  = pathProvider ?? throw new ArgumentNullException(nameof(pathProvider));
     m_Command       = model ?? throw new ArgumentNullException(nameof(model));
     m_Conifguration = configuration ?? throw new ArgumentNullException(nameof(configuration));
 }
Ejemplo n.º 2
0
        private void Approve(CommandDocumentation model, CommandLineHelpConfiguration?configuration = null)
        {
            var pathProvider = new DefaultCommandLineHelpPathProvider();
            var documentSet  = new DocumentSet <IDocument>();

            configuration ??= new ConfigurationProvider().GetDefaultCommandLineHelpConfiguration();

            var commandPage = new CommandPage(documentSet, pathProvider, model, configuration);

            // add dummy application page and command page itself to document set
            // because command page will create a link to the application page
            // which would fail otherwise
            documentSet.Add(pathProvider.GetPath(model.Application), new TextDocument());
            documentSet.Add(pathProvider.GetPath(model), commandPage);

            var doc = commandPage.GetDocument();

            Assert.NotNull(doc);

            var markdown = doc.ToString();

            var writer = new ApprovalTextWriter(markdown);

            Approvals.Verify(writer, new ApprovalNamer(relativeOutputDirectory: "../../../_referenceResults"), Approvals.GetReporter());
        }
Ejemplo n.º 3
0
 public void Help(string command = null, string subcommand = null)
 {
     if (command == null)
     {
         Console.WriteLine("Available commands:");
         foreach (var cmd in CommandRepository.CommandList)
         {
             var permLevel = cmd.GetCustomAttribute <AccessLevel>();
             if (permLevel == null || Sender.PermissionLevel >= permLevel.MinimumLevel)
             {
                 Console.WriteLine(cmd.SyntaxDocumentation(Sender));
             }
         }
     }
     else
     {
         var    repository  = (DefaultCommandRepository <User>)CommandRepository;
         string commandName = subcommand == null ? command : $"{command} {subcommand}";
         var    cmdDelegate = repository.GetDelegate(command, subcommand);
         if (cmdDelegate == null)
         {
             Fail(string.Format(TextOptions.CommandNotFound, commandName));
         }
         // If the user doesn't have permission to run this command, don't show it
         var         baseCmdDelegate = repository.GetDelegate(command);
         AccessLevel permLevel       = baseCmdDelegate.GetCustomAttribute <AccessLevel>();
         AccessLevel subPermLevel    = cmdDelegate.GetCustomAttribute <AccessLevel>();
         if ((permLevel != null && permLevel.MinimumLevel > Sender.PermissionLevel) ||
             (subPermLevel != null && subPermLevel.MinimumLevel > Sender.PermissionLevel))
         {
             Fail(string.Format(TextOptions.CommandNotFound, commandName));
         }
         CommandDocumentation documentation = cmdDelegate.GetCustomAttribute <CommandDocumentation>();
         string helpText = documentation == null ? "This command does not have any documentation." : documentation.Documentation;
         string aliases  = string.Join(", ", cmdDelegate.Aliases);
         if (cmdDelegate is CommandGroupDelegate <User> groupDelegate)
         {
             if (aliases.Length > 0)
             {
                 aliases = " Aliases: " + aliases + ".";
             }
             Console.WriteLine($"{helpText}{aliases} Subcommands:\n{groupDelegate.SubcommandList(Sender)}");
         }
         else
         {
             if (aliases.Length > 0)
             {
                 aliases = ". Aliases: " + aliases;
             }
             Console.WriteLine($"{helpText} Syntax: {cmdDelegate.SyntaxDocumentation(Sender)}{aliases}");
         }
     }
 }
Ejemplo n.º 4
0
        public CecilCommandDescriptor(TypeDefinition typeDef, IDictionary <string, object> commandAttribute, IEnumerable <CecilCommandInputDescriptor> inputs)
        {
            Visible   = true;
            IsDefault = false;
            commandAttribute.TryGet("Noun", noun => Noun                = (string)noun);
            commandAttribute.TryGet("Verb", verb => Verb                = (string)verb);
            commandAttribute.TryGet("Visible", visible => Visible       = (bool)visible);
            commandAttribute.TryGet("IsDefault", isDefault => IsDefault = (bool)isDefault);
            var tokenPrefix = Verb + "-" + Noun;

            commandAttribute.TryGet("Description", _ => Description = (string)_);
            Description = Description ?? CommandDocumentation.GetCommandDescription(typeDef.Module.Assembly, tokenPrefix);
            Inputs      = inputs.ToDictionary(x => x.Name,
                                              x =>
            {
                x.Description = x.Description ?? CommandDocumentation.GetCommandDescription(typeDef.Module.Assembly, tokenPrefix + "-" + x.Name);
                return((ICommandInputDescriptor)x);
            }, StringComparer.OrdinalIgnoreCase);

            Factory = () => (ICommand)Activator.CreateInstanceFrom(typeDef.Module.FullyQualifiedName, typeDef.FullName).Unwrap();
        }
Ejemplo n.º 5
0
 public string GetPath(CommandDocumentation model) => $"commands/{model.Name}.md";
Ejemplo n.º 6
0
 private void RegisterCommandPage(CommandDocumentation command) =>
 m_DocumentSet.Add(m_PathProvider.GetPath(command), new CommandPage(m_DocumentSet, m_PathProvider, command, m_Configuration));
Ejemplo n.º 7
0
 public NamedCommandUsageSection(CommandDocumentation command) : base(command)
 {
     m_Command = command ?? throw new ArgumentNullException(nameof(command));
 }