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 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 Print(CommandTextWriter writer, CommandMethodDescriptor[] descriptors) { this.PrintSummary(writer); this.PrintDescription(writer, descriptors); this.PrintUsage(writer, descriptors); this.PrintExample(writer); this.PrintSubcommands(writer, descriptors); }
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(); } }
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(); } }
private void PrintSummary(CommandTextWriter writer, CommandMethodDescriptor descriptor, CommandMemberDescriptor[] _) { if (descriptor.Summary != string.Empty) { writer.BeginGroup(Resources.Text_Summary); writer.WriteMultiline(descriptor.Summary); writer.EndGroup(); } }
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); }
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 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(); } }
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); } }
private void PrintSummary(CommandTextWriter writer) { var summary = this.Summary; if (summary != string.Empty) { writer.BeginGroup(Resources.Text_Summary); writer.WriteMultiline(summary); 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 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); } }
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); } }
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(); } }
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()); } }
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 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 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 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 EndGroup(CommandTextWriter writer) { writer.EndGroup(); }
private void PrintUsage(CommandTextWriter writer, CommandMemberDescriptor descriptor) { writer.BeginGroup(Resources.Text_Usage); writer.WriteLine(this.GetString(descriptor)); writer.EndGroup(); }
private void PrintDescription(CommandTextWriter writer, CommandMemberDescriptor descriptor) { writer.BeginGroup(Resources.Text_Description); writer.WriteLine(descriptor.Description); writer.EndGroup(); }
private void BeginGroup(CommandTextWriter writer, string text) { writer.BeginGroup(text); }
private void PrintVariables(CommandTextWriter writer, CommandMemberDescriptor descriptor) { writer.BeginGroup(descriptor.Name + " ..."); writer.WriteMultiline(descriptor.Description); writer.EndGroup(); }
private void Print(CommandTextWriter writer, CommandMethodDescriptor descriptor, CommandMemberDescriptor memberDescriptor) { this.PrintSummary(writer, descriptor, memberDescriptor); this.PrintDescription(writer, descriptor, memberDescriptor); this.PrintUsage(writer, descriptor, memberDescriptor); }
private void PrintDescription(CommandTextWriter writer, CommandMethodDescriptor _, CommandMemberDescriptor memberDescriptor) { writer.BeginGroup(Resources.Text_Description); writer.WriteMultiline(memberDescriptor.Description); writer.EndGroup(); }
private void PrintUsage(CommandTextWriter writer, CommandMethodDescriptor descriptor, CommandMemberDescriptor[] memberDescriptors) { this.BeginGroup(writer, Resources.Text_Usage); this.PrintMethodUsage(writer, descriptor, memberDescriptors); this.EndGroup(writer); }
private void PrintUsage(CommandTextWriter writer, CommandMethodDescriptor _, CommandMemberDescriptor memberDescriptor) { this.BeginGroup(writer, Resources.Text_Usage); this.PrintOption(writer, memberDescriptor, false); this.EndGroup(writer); }