Inheritance: System.CodeDom.Compiler.IndentedTextWriter
コード例 #1
0
 public virtual void Print(TextWriter writer, SwitchDescriptor[] switches)
 {
     using (var tw = new CommandTextWriter(writer))
     {
         this.Print(tw, switches);
     }
 }
コード例 #2
0
        protected override void OnExecute()
        {
            try
            {
                if (this.CommandName == string.Empty)
                {
                    using (var writer = new CommandTextWriter(this.commandContext.Out))
                    {
                        this.PrintList(writer);
                    }
                }
                else
                {
                    var command = this.commandContext.Commands[this.CommandName];
                    if (this.commandContext.IsCommandVisible(command) == false)
                        throw new CommandNotFoundException(string.Format(Resources.CommandNotFound_Format, command));

                    var parser = this.commandContext.Parsers[command];
                    parser.Out = this.commandContext.Out;
                    this.PrintUsage(command, parser);
                }
            }
            finally
            {
                this.CommandName = string.Empty;
            }
        }
コード例 #3
0
 protected override void OnExecute()
 {
     var info = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location);
     using (var writer = new CommandTextWriter(this.commandContext.Out))
     {
         if (this.IsQuiet == false)
         {
             writer.WriteLine(string.Join(" ", this.commandContext.Name, this.commandContext.Version).Trim());
             writer.WriteLine(info.LegalCopyright);
         }
         else
         {
             writer.WriteLine(this.commandContext.Version);
         }
     }
 }
コード例 #4
0
        private void PrintList(CommandTextWriter writer)
        {
            this.commandContext.Parsers[this].PrintUsage();

            writer.WriteLine(Resources.AvaliableCommands);
            writer.Indent++;
            foreach (var item in this.commandContext.Commands)
            {
                if (this.commandContext.IsCommandVisible(item) == false)
                    continue;
                var summary = CommandDescriptor.GetUsageDescriptionProvider(item.GetType()).GetSummary(item);

                writer.WriteLine(item.Name);
                writer.Indent++;
                writer.WriteMultiline(summary);
                writer.Indent--;
            }
            writer.Indent--;
        }
コード例 #5
0
        private void PrintSummary(CommandTextWriter writer, SwitchDescriptor[] switches)
        {
            if (this.Summary == string.Empty)
                return;

            writer.WriteLine(Resources.Summary);
            writer.Indent++;
            writer.WriteLine(this.Summary);
            writer.Indent--;
            writer.WriteLine();
        }
コード例 #6
0
        private void PrintUsage(CommandTextWriter writer, SwitchDescriptor[] switches)
        {
            var query = from item in switches
                        orderby item.Required descending
                        select this.GetString(item);

            var maxWidth = writer.Width - (writer.TabString.Length * writer.Indent);

            var line = this.Name;

            writer.WriteLine(Resources.Usage);
            writer.Indent++;

            foreach (var item in query)
            {
                if (line != string.Empty)
                    line += " ";

                if (line.Length + item.Length >= maxWidth)
                {
                    writer.WriteLine(line);
                    line = string.Empty.PadLeft(this.Name.Length + 1);
                }
                line += item;
            }
            writer.WriteLine(line);

            writer.Indent--;
            writer.WriteLine();
        }
コード例 #7
0
        private void PrintRequirements(CommandTextWriter writer, SwitchDescriptor[] switches)
        {
            var items = switches.Where(i => i.Required == true).ToArray();
            if (items.Any() == false)
                return;

            writer.WriteLine(Resources.Requirements);
            writer.Indent++;
            foreach (var item in items)
            {
                this.PrintRequirement(writer, item);
            }
            writer.Indent--;
            writer.WriteLine();
        }
コード例 #8
0
 private void PrintRequirement(CommandTextWriter writer, SwitchDescriptor descriptor)
 {
     writer.WriteLine(descriptor.Name);
     if (descriptor.Description != string.Empty)
     {
         writer.Indent++;
         writer.WriteMultiline(descriptor.Description);
         writer.Indent--;
     }
     writer.WriteLine();
 }
コード例 #9
0
        private void PrintOption(CommandTextWriter writer, SwitchDescriptor descriptor)
        {
            if (descriptor.ShortNamePattern != string.Empty)
                writer.WriteLine(descriptor.ShortNamePattern);
            if (descriptor.NamePattern != string.Empty)
                writer.WriteLine(descriptor.NamePattern);

            writer.Indent++;
            writer.WriteMultiline(descriptor.Description);
            writer.Indent--;
            writer.WriteLine();
        }
コード例 #10
0
        private void PrintDescription(CommandTextWriter writer, SwitchDescriptor[] switches)
        {
            if (this.Description == string.Empty)
                return;

            writer.WriteLine(Resources.Description);
            writer.Indent++;
            writer.WriteMultiline(this.Description);
            writer.Indent--;
            writer.WriteLine();
        }
コード例 #11
0
 private void Print(CommandTextWriter writer, SwitchDescriptor[] switches)
 {
     this.PrintSummary(writer, switches);
     this.PrintUsage(writer, switches);
     this.PrintDescription(writer, switches);
     this.PrintRequirements(writer, switches);
     this.PrintOptions(writer, switches);
 }