MCPcopy Create free account
hub / github.com/Keeper-Security/Commander / read_command_with_continuation

Function read_command_with_continuation

keepercommander/cli.py:807–841  ·  view source on GitHub ↗

Read command with support for line continuation using backslash.

(prompt_session, params)

Source from the content-addressed store, hash-verified

805
806
807def read_command_with_continuation(prompt_session, params):
808 """Read command with support for line continuation using backslash."""
809 command_lines = []
810 continuation_prompt = "... "
811 current_prompt = get_prompt(params)
812
813 while True:
814 if prompt_session is not None:
815 line = prompt_session.prompt(current_prompt)
816 else:
817 line = input(current_prompt)
818
819 # Check if line ends with backslash (line continuation)
820 # First strip all trailing whitespace, then check for backslash
821 stripped_line = line.rstrip()
822 if stripped_line.endswith('\\'):
823 # Remove the backslash and any remaining whitespace
824 line_content = stripped_line[:-1].strip()
825 if line_content: # Only add non-empty lines
826 command_lines.append(line_content)
827 current_prompt = continuation_prompt
828 else:
829 # No continuation, add the final line if it has content
830 line_content = stripped_line
831 if line_content:
832 command_lines.append(line_content)
833 break
834
835 # Join all lines with spaces, ensuring no extra spaces
836 # Also clean up any multiple spaces that might have been introduced
837 result = ' '.join(command_lines)
838 # Replace multiple spaces with single spaces to handle any remaining formatting issues
839 import re
840 result = re.sub(r'\s+', ' ', result).strip()
841 return result
842
843
844def loop(params, skip_init=False, suppress_goodbye=False, new_login=False): # type: (KeeperParams, bool, bool, bool) -> int # suppress_goodbye kept for API compat

Calls 2

get_promptFunction · 0.85
promptMethod · 0.80