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

Function loop

keepercommander/cli.py:747–886  ·  view source on GitHub ↗
(params, skip_init=False, suppress_goodbye=False, new_login=False)

Source from the content-addressed store, hash-verified

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
748 global prompt_session
749 error_no = 0
750 suppress_errno = False
751
752 logging.getLogger().setLevel(logging.DEBUG if params.debug else logging.WARNING if params.batch_mode else logging.INFO)
753 enforcement_checked = set()
754 prompt_session = None
755 if not params.batch_mode:
756 if os.isatty(0) and os.isatty(1):
757 completer = CommandCompleter(params, aliases)
758 # Create key bindings with Ctrl+Q to exit (consistent with supershell)
759 bindings = KeyBindings()
760 @bindings.add('c-q')
761 def _(event):
762 """Exit shell on Ctrl+Q"""
763 event.app.exit(exception=EOFError)
764 prompt_session = PromptSession(multiline=False,
765 editing_mode=EditingMode.VI,
766 completer=completer,
767 complete_style=CompleteStyle.MULTI_COLUMN,
768 complete_while_typing=False,
769 key_bindings=bindings)
770
771 if not skip_init:
772 display.welcome()
773 versioning.welcome_print_version(params)
774 # Show government warning for GOV environments when entering interactive shell
775 if params.server and 'govcloud' in params.server.lower():
776 display.show_government_warning()
777
778 if not params.batch_mode and not skip_init:
779 if params.user:
780 try:
781 LoginCommand().execute(params, email=params.user, password=params.password, new_login=new_login)
782 except KeyboardInterrupt:
783 logging.info('')
784 except EOFError:
785 return 0
786 except Exception as e:
787 logging.error(e)
788 else:
789 if params.device_token:
790 logging.info('Region: %s', params.server)
791 logging.info('')
792 logging.info("You are not logged in.")
793 logging.info(f'Type {Fore.GREEN}login <email>{Fore.RESET} to authenticate or {Fore.GREEN}server <region>{Fore.RESET} to change data centers.')
794 logging.info(f'Type {Fore.GREEN}?{Fore.RESET} for a list of all available commands.')
795
796 # Mark that we're in the shell loop (used by supershell to know if it should start a shell on exit)
797 params._in_shell_loop = True
798
799 # NB! USE_LOCAL_DAG=TRUE should be used only for testing. Warn here — after the
800 # login/decrypt output, right before the first prompt — so the notice isn't buried:
801 # the local test DAG engine routes PAM/DAG/discovery commands to a local SQLite
802 # graph instead of the gateway/router, so they may fail or behave incorrectly
803 # until it is disabled or removed.
804 if not params.batch_mode and not skip_init:

Callers

nothing calls this directly

Calls 15

CommandCompleterClass · 0.85
LoginCommandClass · 0.85
do_commandFunction · 0.85
getMethod · 0.80
warningMethod · 0.80
value_to_booleanFunction · 0.70
executeMethod · 0.45
infoMethod · 0.45
errorMethod · 0.45
updateMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected