示例#1
0
 def testCompleteCallsFindCompletionsWithCorrectArgs(self):
     self._SetCompletionContext('gcloud fruits man', '17')
     find_completions_mock = self.StartObjectPatch(lookup,
                                                   '_FindCompletions')
     lookup.Complete()
     find_completions_mock.assert_called_with(self.root,
                                              'gcloud fruits man')
示例#2
0
def main():
    try:
        if '_ARGCOMPLETE' in os.environ:
            # pylint:disable=g-import-not-at-top
            import googlecloudsdk.command_lib.static_completion.lookup as lookup
            lookup.Complete(_GCLOUD_PY_DIR)
            return
    # pylint:disable=broad-except
    except Exception:
        # Users do not expect to see errors during completion!
        pass

    # pylint:disable=g-import-not-at-top
    try:
        import googlecloudsdk.gcloud_main
    except ImportError as err:
        # We DON'T want to suggest `gcloud components reinstall` here (ex. as
        # opposed to the similar message in gcloud_main.py), as we know that no
        # commands will work.
        sys.stderr.write((
            'ERROR: gcloud failed to load: {0}\n\n'
            'This usually indicates corruption in your gcloud installation or '
            'problems with your Python interpreter.\n\n'
            'Please verify that the following is the path to a working Python 2.7 '
            'executable:\n'
            '    {1}\n\n'
            'If it is not, please set the CLOUDSDK_PYTHON environment variable to '
            'point to a working Python 2.7 executable.\n\n'
            'If you are still experiencing problems, please reinstall the Cloud '
            'SDK using the instructions here:\n'
            '    https://cloud.google.com/sdk/\n').format(err, sys.executable))
        sys.exit(1)
    sys.exit(googlecloudsdk.gcloud_main.main())
示例#3
0
 def testCompleteWritesCompletionsToStream(self):
     self._SetCompletionContext('gcloud alpha int', '16')
     find_completions_mock = self.StartObjectPatch(lookup,
                                                   '_FindCompletions')
     find_completions_mock.return_value = ['internal']
     lookup.Complete()
     self.assertTrue(self.completions_closed)
     self.assertEqual(b'internal', self.completions_value)
def main():
    sys.path = reorder_sys_path(sys.path)
    # pylint:disable=g-import-not-at-top
    from googlecloudsdk.core.util import encoding

    if encoding.GetEncodedValue(os.environ, '_ARGCOMPLETE'):
        try:
            # pylint:disable=g-import-not-at-top
            import googlecloudsdk.command_lib.static_completion.lookup as lookup
            lookup.Complete()
            return
        except Exception:  # pylint:disable=broad-except, hide completion errors
            if encoding.GetEncodedValue(os.environ,
                                        '_ARGCOMPLETE_TRACE') == 'static':
                raise

    try:
        _fix_google_module()
        gcloud_main = _import_gcloud_main()
    except Exception as err:  # pylint: disable=broad-except
        # We want to catch *everything* here to display a nice message to the user
        # pylint:disable=g-import-not-at-top
        import traceback
        # We DON'T want to suggest `gcloud components reinstall` here (ex. as
        # opposed to the similar message in gcloud_main.py), as we know that no
        # commands will work.
        sys.stderr.write((
            'ERROR: gcloud failed to load: {0}\n{1}\n\n'
            'This usually indicates corruption in your gcloud installation or '
            'problems with your Python interpreter.\n\n'
            'Please verify that the following is the path to a working Python 2.7 '
            'or 3.5+ executable:\n'
            '    {2}\n\n'
            'If it is not, please set the CLOUDSDK_PYTHON environment variable to '
            'point to a working Python 2.7 or 3.5+ executable.\n\n'
            'If you are still experiencing problems, please reinstall the Cloud '
            'SDK using the instructions here:\n'
            '    https://cloud.google.com/sdk/\n').format(
                err, '\n'.join(traceback.format_exc().splitlines()[2::2]),
                sys.executable))
        sys.exit(1)
    sys.exit(gcloud_main.main())
示例#5
0
 def testLookupCompletion(self):
     lookup.Complete()
     self.assertEqual('--help', self.completions_value)