Format a command line to display on a single line. Spaces and newlines in quotes are preserved so those strings will span multiple lines. :param statement: Statement being formatted. :return: formatted command line
(statement: Statement)
| 20 | |
| 21 | |
| 22 | def single_line_format(statement: Statement) -> str: |
| 23 | """Format a command line to display on a single line. |
| 24 | |
| 25 | Spaces and newlines in quotes are preserved so those strings will span multiple lines. |
| 26 | |
| 27 | :param statement: Statement being formatted. |
| 28 | :return: formatted command line |
| 29 | """ |
| 30 | if not statement.raw: |
| 31 | return "" |
| 32 | |
| 33 | lines = statement.raw.splitlines() |
| 34 | formatted_command = lines[0] |
| 35 | |
| 36 | # Append any remaining lines to the command. |
| 37 | for line in lines[1:]: |
| 38 | try: |
| 39 | shlex_split(formatted_command) |
| 40 | except ValueError: |
| 41 | # We are in quotes, so restore the newline. |
| 42 | separator = "\n" |
| 43 | else: |
| 44 | # Don't add a space before line if one already exists or if it begins with the terminator. |
| 45 | if ( |
| 46 | formatted_command.endswith(" ") |
| 47 | or line.startswith(" ") |
| 48 | or (statement.terminator and line.startswith(statement.terminator)) |
| 49 | ): |
| 50 | separator = "" |
| 51 | else: |
| 52 | separator = " " |
| 53 | |
| 54 | formatted_command += separator + line |
| 55 | |
| 56 | return formatted_command |
| 57 | |
| 58 | |
| 59 | @dataclass(frozen=True) |
searching dependent graphs…