Example #1
0
def main(args=None):
    """Main CumulusCI CLI entry point.

    This runs as the first step in processing any CLI command.

    This wraps the `click` library in order to do some initialization and centralized error handling.
    """
    with contextlib.ExitStack() as stack:
        args = args or sys.argv
        # Check for updates _unless_ we've been asked to output JSON,
        # or if we're going to check anyway as part of the `version` command.
        is_version_command = len(args) > 1 and args[1] == "version"
        if "--json" not in args and not is_version_command:
            check_latest_version()

        # Load CCI config
        global RUNTIME
        RUNTIME = CliRuntime(load_keychain=False)
        RUNTIME.check_cumulusci_version()

        # Configure logging
        debug = "--debug" in args
        if debug:
            args.remove("--debug")

        # Only create logfiles for commands
        # that are not `cci gist`
        is_gist_command = len(args) > 2 and args[2] == "gist"
        if not is_gist_command:
            logger = get_gist_logger()
            stack.enter_context(tee_stdout_stderr(args, logger))

        init_logger(log_requests=debug)
        # Hand CLI processing over to click, but handle exceptions
        try:
            cli(standalone_mode=False)
        except click.Abort:  # Keyboard interrupt
            show_debug_info() if debug else click.echo("\nAborted!")
            sys.exit(1)
        except Exception as e:
            show_debug_info() if debug else handle_exception(
                e, is_gist_command)
            sys.exit(1)
Example #2
0
    def test_check_cumulusci_version(self):
        config = CliRuntime()
        config.project_config.minimum_cumulusci_version = "999"

        with self.assertRaises(click.UsageError):
            config.check_cumulusci_version()