CommandLine
ConsoleMonster.Interactive
Builds the command line equivalent to a set of answers, from each field's parameter name, so every interactive run teaches the non-interactive form. Values are quoted for the chosen style; switches appear only when on.
Inheritance
- object
- CommandLine
Methods
public static string Argument(string name, object? value, CommandStyle style) #Formats one argument: -Name value, a list, or a switch.
Parameters
- name string
- The parameter name.
- value object?
- A string, number, bool (switch) or list.
- style ConsoleMonster.Interactive.CommandStyle
- The style.
Returns
string The argument, or an empty string for an off switch or an empty value.public static string Build(string command, IEnumerable<KeyValuePair<string, object?>> arguments, CommandStyle style = PowerShell) #Builds an equivalent command from named values, retaining their enumeration order.
Parameters
- command string
- The command text.
- arguments System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object?>>
- Named strings, numbers, switches or lists. Empty and disabled arguments are omitted.
- style ConsoleMonster.Interactive.CommandStyle = PowerShell
- The argument quoting style.
Returns
string Command text for display or copying; this method does not execute it.public static string Join(string command, IEnumerable<string> arguments) #Joins a command and its arguments, skipping empty ones.
Parameters
- command string
- The command.
- arguments System.Collections.Generic.IEnumerable<string>
- The arguments.
Returns
string The command line.public static string Parameter(string name, CommandStyle style) #Formats a parameter name for a style (Domain → -Domain, --domain or /domain).
Parameters
- name string
- The name, with or without its prefix.
- style ConsoleMonster.Interactive.CommandStyle
- The style.
Returns
string The parameter as written on the command line.public static string Quote(string value, CommandStyle style) #Quotes a value when the style needs it. Windows uses CommandLineToArgvW-compatible argument encoding.
Parameters
- value string
- The value.
- style ConsoleMonster.Interactive.CommandStyle
- The style.
Returns
string The value as written on the command line.public static IReadOnlyList<string> Wrap(string command, int width) #Wraps a command line for display, breaking between arguments (a parameter stays with its value), then between the items of a list value, and only inside a token when it alone is wider than the line.
Parameters
- command string
- The command line.
- width int
- The line width.
Returns
IReadOnlyList<string> The lines.public static IReadOnlyList<string> Wrap(string command, int width, int indent) #Wraps a command line for display with continuation lines indented. Breaks fall between arguments first (a parameter stays with its value: -Name value); an argument too wide for a line of its own breaks between the items of its list value (after each comma, never inside quotes), with those lines indented twice as far; a parameter and its value part only when they cannot share a line; and a token is cut only when it alone is wider than a line. Widths are terminal cells.
Parameters
- command string
- The command line.
- width int
- The line width (at least 8).
- indent int
- The cells continuation lines start with (at most half the width).
Returns
IReadOnlyList<string> The lines, continuation lines starting with the indent.