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

Function read_command_with_continuation

keepercommander/cli.py:835–869  ·  view source on GitHub ↗

Read command with support for line continuation using backslash.

(prompt_session, params)

Source from the content-addressed store, hash-verified

833
834
835def read_command_with_continuation(prompt_session, params):
836 """Read command with support for line continuation using backslash."""
837 command_lines = []
838 continuation_prompt = "... "
839 current_prompt = get_prompt(params)
840
841 while True:
842 if prompt_session is not None:
843 line = prompt_session.prompt(current_prompt)
844 else:
845 line = input(current_prompt)
846
847 # Check if line ends with backslash (line continuation)
848 # First strip all trailing whitespace, then check for backslash
849 stripped_line = line.rstrip()
850 if stripped_line.endswith('\\'):
851 # Remove the backslash and any remaining whitespace
852 line_content = stripped_line[:-1].strip()
853 if line_content: # Only add non-empty lines
854 command_lines.append(line_content)
855 current_prompt = continuation_prompt
856 else:
857 # No continuation, add the final line if it has content
858 line_content = stripped_line
859 if line_content:
860 command_lines.append(line_content)
861 break
862
863 # Join all lines with spaces, ensuring no extra spaces
864 # Also clean up any multiple spaces that might have been introduced
865 result = ' '.join(command_lines)
866 # Replace multiple spaces with single spaces to handle any remaining formatting issues
867 import re
868 result = re.sub(r'\s+', ' ', result).strip()
869 return result
870
871
872def 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