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

Function loop

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

Source from the content-addressed store, hash-verified

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
845 global prompt_session
846 error_no = 0
847 suppress_errno = False
848
849 logging.getLogger().setLevel(logging.DEBUG if params.debug else logging.WARNING if params.batch_mode else logging.INFO)
850 enforcement_checked = set()
851 prompt_session = None
852 if not params.batch_mode:
853 if os.isatty(0) and os.isatty(1):
854 completer = CommandCompleter(params, aliases)
855 # Create key bindings with Ctrl+Q to exit (consistent with supershell)
856 bindings = KeyBindings()
857 @bindings.add('c-q')
858 def _(event):
859 """Exit shell on Ctrl+Q"""
860 event.app.exit(exception=EOFError)
861 prompt_session = PromptSession(multiline=False,
862 editing_mode=EditingMode.VI,
863 completer=completer,
864 complete_style=CompleteStyle.MULTI_COLUMN,
865 complete_while_typing=False,
866 key_bindings=bindings)
867
868 if not skip_init:
869 display.welcome()
870 versioning.welcome_print_version(params)
871 # Show government warning for GOV environments when entering interactive shell
872 if params.server and 'govcloud' in params.server.lower():
873 display.show_government_warning()
874
875 if not params.batch_mode and not skip_init:
876 if params.user:
877 try:
878 LoginCommand().execute(params, email=params.user, password=params.password, new_login=new_login)
879 except KeyboardInterrupt:
880 logging.info('')
881 except EOFError:
882 return 0
883 except Exception as e:
884 logging.error(e)
885 else:
886 if params.device_token:
887 logging.info('Region: %s', params.server)
888 logging.info('')
889 logging.info("You are not logged in.")
890 logging.info(f'Type {Fore.GREEN}login <email>{Fore.RESET} to authenticate or {Fore.GREEN}server <region>{Fore.RESET} to change data centers.')
891 logging.info(f'Type {Fore.GREEN}?{Fore.RESET} for a list of all available commands.')
892
893 # Mark that we're in the shell loop (used by supershell to know if it should start a shell on exit)
894 params._in_shell_loop = True
895
896 # NB! USE_LOCAL_DAG=TRUE should be used only for testing. Warn here — after the
897 # login/decrypt output, right before the first prompt — so the notice isn't buried:
898 # the local test DAG engine routes PAM/DAG/discovery commands to a local SQLite
899 # graph instead of the gateway/router, so they may fail or behave incorrectly
900 # until it is disabled or removed.
901 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
warningMethod · 0.80
value_to_booleanFunction · 0.70
executeMethod · 0.45
infoMethod · 0.45
errorMethod · 0.45
getMethod · 0.45
updateMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected