コード例 #1
0
        private void PrintMethodUsage(CommandTextWriter writer, CommandMethodDescriptor descriptor, CommandMemberDescriptor[] memberDescriptors)
        {
            var indent = writer.Indent;
            var query  = from item in memberDescriptors
                         where item.IsRequired == true || item.IsVariables == true
                         select item;
            var maxWidth = writer.Width - (writer.TabString.Length * writer.Indent);
            var line     = this.Name + " " + descriptor.Name;

            if (this.Aliases.Any() == true)
            {
                line += $"({string.Join(",", this.Aliases)})";
            }
            foreach (var item in query)
            {
                var text = this.GetString(item);
                if (line != string.Empty)
                {
                    line += " ";
                }
                if (line.Length + text.Length >= maxWidth)
                {
                    writer.WriteLine(line);
                    line = string.Empty.PadLeft(descriptor.Name.Length + 1);
                }
                line += text;
            }
            writer.WriteLine(line);
            writer.Indent = indent;
        }
コード例 #2
0
 private void PrintOption(CommandTextWriter writer, CommandMemberDescriptor descriptor, bool isLast)
 {
     if (descriptor.IsSwitch == true)
     {
         writer.WriteLine(descriptor.DisplayName);
     }
     else if (descriptor.DefaultValue == null)
     {
         writer.WriteLine($"{descriptor.DisplayName} 'value' [default: null]");
     }
     else if (descriptor.DefaultValue != DBNull.Value)
     {
         writer.WriteLine($"{descriptor.DisplayName} 'value' [default: '{descriptor.DefaultValue}']");
     }
     else
     {
         writer.WriteLine($"{descriptor.DisplayName} 'value'");
     }
     if (descriptor.Summary != string.Empty && this.Usage != CommandUsage.Simple)
     {
         writer.Indent++;
         writer.WriteMultiline(descriptor.Summary);
         writer.Indent--;
     }
     if (isLast == false)
     {
         writer.WriteLine();
     }
 }
コード例 #3
0
 private void Print(CommandTextWriter writer, CommandMethodDescriptor[] descriptors)
 {
     this.PrintSummary(writer);
     this.PrintDescription(writer, descriptors);
     this.PrintUsage(writer, descriptors);
     this.PrintExample(writer);
     this.PrintSubcommands(writer, descriptors);
 }
コード例 #4
0
 private void PrintExample(CommandTextWriter writer, CommandMethodDescriptor descriptor, CommandMemberDescriptor[] _)
 {
     if (descriptor.Example != string.Empty && this.Usage != CommandUsage.Simple)
     {
         writer.BeginGroup(Resources.Text_Example);
         writer.WriteMultiline(descriptor.Example);
         writer.EndGroup();
     }
 }
コード例 #5
0
 private void PrintDescription(CommandTextWriter writer, CommandMethodDescriptor descriptor, CommandMemberDescriptor[] _)
 {
     if (descriptor.Description != string.Empty && this.IsDetail == true)
     {
         writer.BeginGroup(Resources.Text_Description);
         writer.WriteMultiline(descriptor.Description);
         writer.EndGroup();
     }
 }
コード例 #6
0
 private void PrintSummary(CommandTextWriter writer, CommandMethodDescriptor descriptor, CommandMemberDescriptor[] _)
 {
     if (descriptor.Summary != string.Empty)
     {
         writer.BeginGroup(Resources.Text_Summary);
         writer.WriteMultiline(descriptor.Summary);
         writer.EndGroup();
     }
 }
コード例 #7
0
 private void Print(CommandTextWriter writer, CommandMethodDescriptor descriptor, CommandMemberDescriptor[] memberDescriptors)
 {
     this.PrintSummary(writer, descriptor, memberDescriptors);
     this.PrintDescription(writer, descriptor, memberDescriptors);
     this.PrintUsage(writer, descriptor, memberDescriptors);
     this.PrintExample(writer, descriptor, memberDescriptors);
     this.PrintRequirements(writer, descriptor, memberDescriptors);
     this.PrintVariables(writer, descriptor, memberDescriptors);
     this.PrintOptions(writer, descriptor, memberDescriptors);
 }
コード例 #8
0
 private void PrintVariables(CommandTextWriter writer, CommandMemberDescriptor descriptor)
 {
     writer.WriteLine(descriptor.DisplayName);
     if (descriptor.Summary != string.Empty)
     {
         writer.Indent++;
         writer.WriteMultiline(descriptor.Summary);
         writer.Indent--;
     }
 }
コード例 #9
0
        private void PrintExample(CommandTextWriter writer)
        {
            var example = this.Example;

            if (example != string.Empty && this.Usage != CommandUsage.Simple)
            {
                writer.BeginGroup(Resources.Text_Example);
                writer.WriteMultiline(example);
                writer.EndGroup();
            }
        }
コード例 #10
0
        private void PrintVariables(CommandTextWriter writer, CommandMethodDescriptor _, CommandMemberDescriptor[] memberDescriptors)
        {
            var variables = memberDescriptors.FirstOrDefault(item => item.Usage == CommandPropertyUsage.Variables);

            if (variables != null && this.Usage != CommandUsage.Simple)
            {
                this.BeginGroup(writer, Resources.Text_Variables);
                this.PrintVariables(writer, variables);
                this.EndGroup(writer);
            }
        }
コード例 #11
0
        private void PrintSummary(CommandTextWriter writer)
        {
            var summary = this.Summary;

            if (summary != string.Empty)
            {
                writer.BeginGroup(Resources.Text_Summary);
                writer.WriteMultiline(summary);
                writer.EndGroup();
            }
        }
コード例 #12
0
        private void PrintUsage(CommandTextWriter writer, CommandMethodDescriptor[] _)
        {
            writer.BeginGroup(Resources.Text_Usage);
            var name = this.Name;

            if (this.Aliases.Any() == true)
            {
                name += $"({string.Join(",", this.Aliases)})";
            }
            writer.WriteLine("{0} <sub-command> [options...]", name);
            writer.EndGroup();
        }
コード例 #13
0
        private void PrintRequirements(CommandTextWriter writer, CommandMemberDescriptor[] descriptors)
        {
            var items = descriptors.Where(item => item.IsRequired == true);

            if (items.Any() == true && this.Usage != CommandUsage.Simple)
            {
                this.BeginGroup(writer, Resources.Text_Requirements);
                foreach (var item in items)
                {
                    this.PrintRequirement(writer, item, items.Last() == item);
                }
                this.EndGroup(writer);
            }
        }
コード例 #14
0
        private void PrintOptions(CommandTextWriter writer, CommandMethodDescriptor _, CommandMemberDescriptor[] memberDescriptors)
        {
            var items = memberDescriptors.Where(item => item.Usage == CommandPropertyUsage.General || item.Usage == CommandPropertyUsage.Switch);

            if (items.Any() == true && this.Usage != CommandUsage.Simple)
            {
                this.BeginGroup(writer, Resources.Text_Options);
                foreach (var item in items)
                {
                    this.PrintOption(writer, item, items.Last() == item);
                }
                this.EndGroup(writer);
            }
        }
コード例 #15
0
 private void PrintRequirement(CommandTextWriter writer, CommandMemberDescriptor descriptor, bool isLast)
 {
     writer.WriteLine(descriptor.DisplayName);
     if (descriptor.Summary != string.Empty)
     {
         writer.Indent++;
         writer.WriteMultiline(descriptor.Summary);
         writer.Indent--;
     }
     if (isLast == false)
     {
         writer.WriteLine();
     }
 }
コード例 #16
0
 public virtual void Print(TextWriter writer, CommandMethodDescriptor descriptor, CommandMemberDescriptor memberDescriptor)
 {
     if (writer is CommandTextWriter commandWriter)
     {
         this.Print(commandWriter, descriptor, memberDescriptor);
     }
     else
     {
         using var tw = new CommandTextWriter()
               {
                   IsAnsiSupported = this.IsAnsiSupported
               };
         this.Print(tw, descriptor, memberDescriptor);
         writer.Write(tw.ToString());
     }
 }
コード例 #17
0
        private void PrintRequirements(CommandTextWriter writer, CommandMethodDescriptor _, CommandMemberDescriptor[] memberDescriptors)
        {
            var items = memberDescriptors.Where(item => item.IsRequired == true).ToArray();

            if (items.Any() == true && this.Usage != CommandUsage.Simple)
            {
                writer.BeginGroup(Resources.Text_Requirements);
                for (var i = 0; i < items.Length; i++)
                {
                    var item = items[i];
                    this.PrintRequirement(writer, item);
                    if (i + 1 < items.Length)
                    {
                        writer.WriteLine();
                    }
                }
                writer.EndGroup();
            }
        }
コード例 #18
0
 private void PrintSubcommands(CommandTextWriter writer, CommandMethodDescriptor[] descriptors)
 {
     writer.BeginGroup(Resources.Text_Subcommands);
     foreach (var item in descriptors)
     {
         var name = GetNames(item);
         writer.WriteLine(name);
         if (item.Summary != string.Empty && this.Usage != CommandUsage.Simple)
         {
             writer.Indent++;
             writer.WriteMultiline(item.Summary);
             writer.Indent--;
         }
         if (descriptors.Last() != item && this.Usage != CommandUsage.Simple)
         {
             writer.WriteLine();
         }
     }
     writer.EndGroup();
 }
コード例 #19
0
        private void PrintRequirement(CommandTextWriter writer, CommandMemberDescriptor descriptor)
        {
            if (descriptor.IsRequired == true)
            {
                writer.WriteLine(descriptor.DisplayName);
            }
            else
            {
                writer.WriteLine(descriptor.DisplayName);
            }

            var description = descriptor.Summary != string.Empty ? descriptor.Summary : descriptor.Description;

            if (description != string.Empty)
            {
                writer.Indent++;
                writer.WriteMultiline(description);
                writer.Indent--;
            }
        }
コード例 #20
0
        private void PrintList()
        {
            using var writer = new CommandTextWriter()
                  {
                      IsAnsiSupported = this.IsAnsiSupported
                  };
            var parser = new CommandLineParser(this.ExecutionName, this)
            {
                Out = writer
            };
            var query = from item in this.CommandContext.Node.Childs
                        where item.IsEnabled == true
                        orderby item.Name
                        select item;

            parser.PrintUsage(string.Empty, this.Usage);
            writer.WriteLine(Resources.Text_AvaliableCommands);
            writer.Indent++;

            foreach (var item in query)
            {
                var descriptor = item.Descriptor;
                var summary    = descriptor != null ? descriptor.Summary : string.Empty;
                var name       = GetCommandNames(item);
                writer.WriteLine(name);
                if (summary != string.Empty && this.Usage != CommandUsage.Simple)
                {
                    writer.Indent++;
                    writer.WriteMultiline(summary);
                    writer.Indent--;
                }
                if (query.Last() != item && this.Usage != CommandUsage.Simple)
                {
                    writer.WriteLine();
                }
            }
            writer.Indent--;
            this.Out.Write(writer.ToString());
        }
コード例 #21
0
        protected override void OnExecute()
        {
            using var writer = new CommandTextWriter(this.Out);
            var name     = this.CommandContext.Name;
            var version  = this.CommandContext.Version;
            var assembly = Assembly.GetEntryAssembly();

            if (assembly == null)
            {
                throw new System.InvalidOperationException(Resources.Exception_UnknownVersion);
            }
            var info = FileVersionInfo.GetVersionInfo(assembly.Location);

            if (this.IsQuiet == false)
            {
                writer.WriteLine($"{name} {version}");
                writer.WriteLine(info.LegalCopyright);
            }
            else
            {
                writer.WriteLine(version);
            }
        }
コード例 #22
0
 private void EndGroup(CommandTextWriter writer)
 {
     writer.EndGroup();
 }
コード例 #23
0
 private void PrintUsage(CommandTextWriter writer, CommandMemberDescriptor descriptor)
 {
     writer.BeginGroup(Resources.Text_Usage);
     writer.WriteLine(this.GetString(descriptor));
     writer.EndGroup();
 }
コード例 #24
0
 private void PrintDescription(CommandTextWriter writer, CommandMemberDescriptor descriptor)
 {
     writer.BeginGroup(Resources.Text_Description);
     writer.WriteLine(descriptor.Description);
     writer.EndGroup();
 }
コード例 #25
0
 private void BeginGroup(CommandTextWriter writer, string text)
 {
     writer.BeginGroup(text);
 }
コード例 #26
0
 private void PrintVariables(CommandTextWriter writer, CommandMemberDescriptor descriptor)
 {
     writer.BeginGroup(descriptor.Name + " ...");
     writer.WriteMultiline(descriptor.Description);
     writer.EndGroup();
 }
コード例 #27
0
 private void Print(CommandTextWriter writer, CommandMethodDescriptor descriptor, CommandMemberDescriptor memberDescriptor)
 {
     this.PrintSummary(writer, descriptor, memberDescriptor);
     this.PrintDescription(writer, descriptor, memberDescriptor);
     this.PrintUsage(writer, descriptor, memberDescriptor);
 }
コード例 #28
0
 private void PrintDescription(CommandTextWriter writer, CommandMethodDescriptor _, CommandMemberDescriptor memberDescriptor)
 {
     writer.BeginGroup(Resources.Text_Description);
     writer.WriteMultiline(memberDescriptor.Description);
     writer.EndGroup();
 }
コード例 #29
0
 private void PrintUsage(CommandTextWriter writer, CommandMethodDescriptor descriptor, CommandMemberDescriptor[] memberDescriptors)
 {
     this.BeginGroup(writer, Resources.Text_Usage);
     this.PrintMethodUsage(writer, descriptor, memberDescriptors);
     this.EndGroup(writer);
 }
コード例 #30
0
 private void PrintUsage(CommandTextWriter writer, CommandMethodDescriptor _, CommandMemberDescriptor memberDescriptor)
 {
     this.BeginGroup(writer, Resources.Text_Usage);
     this.PrintOption(writer, memberDescriptor, false);
     this.EndGroup(writer);
 }