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();
     }
 }
        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;
        }
 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();
     }
 }
 private void PrintVariables(CommandTextWriter writer, CommandMemberDescriptor descriptor)
 {
     writer.WriteLine(descriptor.DisplayName);
     if (descriptor.Summary != string.Empty)
     {
         writer.Indent++;
         writer.WriteMultiline(descriptor.Summary);
         writer.Indent--;
     }
 }
        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--;
            }
        }
 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();
 }
        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();
        }
        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());
        }
        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);
            }
        }
        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();
            }
        }
 private void PrintDescription(CommandTextWriter writer, CommandMemberDescriptor descriptor)
 {
     writer.BeginGroup(Resources.Text_Description);
     writer.WriteLine(descriptor.Description);
     writer.EndGroup();
 }
 private void PrintUsage(CommandTextWriter writer, CommandMemberDescriptor descriptor)
 {
     writer.BeginGroup(Resources.Text_Usage);
     writer.WriteLine(this.GetString(descriptor));
     writer.EndGroup();
 }
 private void PrintSummary(CommandTextWriter writer, CommandMemberDescriptor descriptor)
 {
     writer.BeginGroup(Resources.Text_Summary);
     writer.WriteLine(descriptor.Summary);
     writer.EndGroup();
 }