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

Function read_command_with_continuation

keepercommander/cli.py:710–744  ·  view source on GitHub ↗

Read command with support for line continuation using backslash.

(prompt_session, params)

Source from the content-addressed store, hash-verified

708
709
710def read_command_with_continuation(prompt_session, params):
711 """Read command with support for line continuation using backslash."""
712 command_lines = []
713 continuation_prompt = "... "
714 current_prompt = get_prompt(params)
715
716 while True:
717 if prompt_session is not None:
718 line = prompt_session.prompt(current_prompt)
719 else:
720 line = input(current_prompt)
721
722 # Check if line ends with backslash (line continuation)
723 # First strip all trailing whitespace, then check for backslash
724 stripped_line = line.rstrip()
725 if stripped_line.endswith('\\'):
726 # Remove the backslash and any remaining whitespace
727 line_content = stripped_line[:-1].strip()
728 if line_content: # Only add non-empty lines
729 command_lines.append(line_content)
730 current_prompt = continuation_prompt
731 else:
732 # No continuation, add the final line if it has content
733 line_content = stripped_line
734 if line_content:
735 command_lines.append(line_content)
736 break
737
738 # Join all lines with spaces, ensuring no extra spaces
739 # Also clean up any multiple spaces that might have been introduced
740 result = ' '.join(command_lines)
741 # Replace multiple spaces with single spaces to handle any remaining formatting issues
742 import re
743 result = re.sub(r'\s+', ' ', result).strip()
744 return result
745
746
747def 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